懒得写思路了,要是那个题需要题意的留言或者私聊
7-1 出生年 (15 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int v[10] = {0};
int main(int argc, char** argv) {
int n, t, i, time;
cin >> n >> t;
for(i = 0; ; i++){
time = n + i;
int cnt = 0;
if(time < 1000) v[0] = 1;
while(time){
int x = time % 10;
v[x] = 1;
time /= 10;
}
for(int i = 0; i < 10; i++) cnt += v[i];
if(cnt == t) break;
for(int i = 0; i < 10; i++) v[i] = 0;
}
printf("%d %04d\n", i, n+i);
return 0;
}
7-2 点赞 (20 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int v[10005] = {0};
int main(int argc, char** argv) {
int n;
cin >> n;
for(int i = 1; i <= n; i++){
int k, num;
cin >> k;
for(int j = 1; j <= k; j++){
cin >> num;
v[num]++;
}
}
int id = 0, cnt = -1;
for(int i = 1; i <= 1000; i++){
if(v[i] >= cnt){
cnt = v[i];
id = i;
}
}
cout << id << " " << cnt << endl;
return 0;
}
7-3 情人节 (15 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
string s, a = "", b = "";
int cnt = 0;
while(1){
cin >> s;
if(s == ".") break;
cnt++;
if(cnt == 2) a = s;
if(cnt == 14) b = s;
}
if(a == "") cout << "Momo... No one is for you ..." << endl;
else if(b == "") cout << a << " is the only one for you..." << endl;
else cout << a << " and " << b << " are inviting you to dinner..." << endl;
return 0;
}
7-4 A乘以B (5 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
long long a, b;
cin >> a >> b;
cout << a*b << endl;
return 0;
}
7-5 A除以B (10 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
double a, b;
cin >> a >> b;
if(b == 0) printf("%.0lf/0=Error\n", a);
else if(b < 0) printf("%.0lf/(%.0lf)=%.2lf\n", a, b, a/b);
else printf("%.0lf/%.0lf=%.2lf\n", a, b, a/b);
return 0;
}
7-6 新世界 (5 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
cout << "Hello World" << endl;
cout << "Hello New World" << endl;
return 0;
}
7-7 古风排版 (20 分)
思路
控制循环来实现转换即可,注意处理要输出的最右边的一列
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
char v[105][105];
int main(int argc, char** argv) {
int n;
cin >> n;getchar();
string s;
getline(cin, s);
for(int i = 1; i <= n; i++) v[i][1] = ' ';
int len = s.size(), lie = (len + n - 1) / n, cnt = 0;
for(int i = lie; i > 0; i--){
for(int j = 1; j <= n; j++){
v[j][i] = s[cnt++];
if(cnt == len) break;
}
if(cnt == len) break;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= lie; j++){
cout << v[i][j];
}
cout << endl;
}
return 0;
}
7-8 最佳情侣身高差 (10 分)
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int n;
cin >> n;
while(n--){
char s; double num;
cin >> s >> num;
if(s == 'M') printf("%.2lf\n", num / 1.09);
else printf("%.2lf\n", num * 1.09);
}
return 0;
}
7-9 人以群分 (25 分)
思路
贪心,评分高的人在一组,评分低的在一组。按照题意两组均分人数,如果是人数是奇数,最中间的那个人分到高分组。
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
int main(int argc, char** argv) {
long long n;
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a+1, a+1+n);
long long sum = 0;
for(int i = 1; i <= n/2; i++) sum -= a[i];
for(int i = n/2+1; i <= n; i++) sum += a[i];
cout << "Outgoing #: " << n - n/2 << endl;
cout << "Introverted #: " << n/2 << endl;
cout << "Diff = " << sum << endl;
return 0;
}
7-10 多项式A除以B (25 分)
数论,不是我的题,可以洛谷搜多项式写模板题。
等我想学数论了再更新这个题。
7-11 悄悄关注 (25 分)
思路
用 set 或者 map 按照题意处理即可。
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
set<string> se;
vector<pair<string, int> > v;
int main(int argc, char** argv) {
int nn, n;
cin >> nn;
string s;
for(int i = 1; i <= nn; i++){
cin >> s;
se.insert(s);
}
cin >> n; int sum = 0;
pair<string, int> a;
for(int i = 1; i <= n; i++){
cin >> a.first >> a.second;
sum += a.second;
v.push_back(a);
}
sort(v.begin(), v.end());
int f = 1; sum /= n;
for(int i = 0; i < n; i++){
if(v[i].second > sum && se.find(v[i].first) == se.end()){
f = 0;
cout << v[i].first << endl;
}
}
if(f) cout << "Bing Mei You" << endl;
return 0;
}
7-12 功夫传人 (25 分)
思路
DFS,根据题意,这是一个题目中的师徒关系是一个树状结构,遇到天选之人去统计即可。
AC代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<int> ma[100005];
double res = 0;
void DFS(int root, double z, double r){
if(ma[root][0] == 0){
res += z * ma[root][1];
return;
}
double tmp = z * (100 - r) / 100.0;
for(int i = 1; i <= ma[root][0]; i++) DFS(ma[root][i], tmp, r);
}
int main(int argc, char** argv) {
int n; double z, r;
cin >> n >> z >> r;
for(int i = 0; i < n; i++){
int num, x;
cin >> num;
ma[i].push_back(num);
if(num == 0) num++;
for(int j = 1; j <= num; j++){
cin >> x;
ma[i].push_back(x);
}
}
DFS(0, z, r);
printf("%d\n", (int)res);
return 0;
}