# PTA乙级

## PTA乙级（寒假刷完计划）

tip**:不要美观，要快（大不了最后格式化）；读题仔细，验证每一个样例！

### 1001 害死人不偿命的(3n+1)猜想(15)

3

5

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
int ans = 0;
while (n != 1) {
if (n % 2 == 0) n = n / 2;
else n = (3 * n + 1) / 2;
ans++;
}
cout << ans << endl;
}


### 1002 写出这个数(20)

100 。

1234567890987654321123456789

yi san wu

#include <bits/stdc++.h>

using namespace std;
string a[11] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};

int main() {
string str;
cin >> str;
int ans = 0;
for (int i = 0; i < str.size(); i++) {
ans += (str[i] - '0');
}
str = to_string(ans);
for (int i = 0; i < str.size(); i++) {
if (i != 0) cout << " ";
cout << a[str[i] - '0'];
}
}



### 1003 我要通过！(20)

“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件，系统就输出“答案正确”，否则输出“答案错误”。

10
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
PT
Whatever
APAAATAA
APT
APATTAA

YES
YES
YES
YES
NO
NO
NO
NO
NO
NO

#include <bits/stdc++.h>

using namespace std;

bool is(string str) {
for (int i = 0; i < str.size(); i++) {
if (str[i] != 'A' && str[i] != 'P' && str[i] != 'T') {
return 0;
}
}
int pos1 = 0, pos2 = 0, cnt1 = 0, cnt2 = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'P') pos1 = i, cnt1++;
if (str[i] == 'T') pos2 = i, cnt2++;
}
if (cnt1 > 1 || cnt2 > 1) return 0;
if (pos2 <= pos1 + 1) return 0;
int x = pos1;
int b = pos2 - pos1 - 1;
int y = str.length() - pos2 - 1;
if (y == b * x) return 1;
else return 0;
}
int main() {
int n;
cin >> n;
while (n--) {
string str;
cin >> str;
if (is(str)) cout << "YES\n";
else cout << "NO\n";
}
}


### 1004 成绩排名(20)

… … …

3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

Mike CS991301
Joe Math990112

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
struct stu {
string name;
string xue;
int num;
} a[MAX];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].name >> a[i].xue >> a[i].num;
}
sort(a, a + n, [](stu a, stu b) {
return a.num > b.num;
});
cout << a[0].name << " " << a[0].xue << endl;
cout << a[n - 1].name << " " << a[n - 1].xue << endl;
}


### 1005 继续(3n+1)猜想(25)

6
3 5 6 7 8 11

7 6

tips:仔细看题意

#include <bits/stdc++.h>

using namespace std;
const int MAX = 110;
int a[MAX];
bool flag[MAX];

void ishave(int n, int x) {
set<int> have;
while (x != 1) {
if (x % 2 == 1) {
x = (3 * x + 1) / 2;
} else {
x = x / 2;
}
have.insert(x);
}
for (int i = 0; i < n; i++) {
if (a[i] == x) continue;
if (have.find(a[i]) != have.end()) {
flag[i] = 1;
}
}
}

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
ishave(n, a[i]);
}
vector<int> ans;
for (int i = 0; i < n; i++) {
if (flag[i] == 0) ans.push_back(a[i]);
}
sort(ans.begin(), ans.end(), [](int a, int b) {
return a > b;
});
for (int i = 0; i < ans.size(); i++) {
if (i != 0) cout << " ";
cout << ans[i];
}
}


### 1006 换个格式输出整数(15)

234

BBSSS1234

23

SS123

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
int b = n / 100;
int s = n / 10 % 10;
int g = n % 10;
string ans = "";
ans += string(b, 'B');
ans += string(s, 'S');
for(int i = 1; i <= g; i++) {
ans += to_string(i);
}
cout << ans << endl;
}


### 1007 素数对猜想(20)

1007 素数对猜想 (20 分)

20

4

#include <bits/stdc++.h>

using namespace std;

bool isp(int x) {
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) return 0;
}
return 1;
}

const int MAX = 1e5 + 10;
int ans[MAX];

void init() {
int tmp = 0;
for (int i = 2; i + 2 < MAX; i++) {
if (isp(i) == 1 && isp(i + 2) == 1) tmp++;
ans[i + 2] = tmp;
}
}

int main() {
init();
int x;
cin >> x;
cout << ans[x] << endl;
}


### 1008 数组元素循环右移问题(20)

6 2
1 2 3 4 5 6

5 6 1 2 3 4

#include <bits/stdc++.h>

using namespace std;

const int MAX = 110;
int a[MAX];

int main() {
int n, k;
cin >> n >> k;
k %= n;
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> ans;
for (int i = n - k + 1; i <= n; i++) ans.push_back(a[i]);
for (int i = 1; i <= n - k; i++) ans.push_back(a[i]);
for (int i = 0; i < ans.size(); i++) {
if (i != 0) cout << " ";
cout << ans[i];
}
}


### 1009 说反话(20)

Hello World Here I Come

Come I Here World Hello

#include <bits/stdc++.h>

using namespace std;
vector<string> ans;

int main() {
string str;
while (cin >> str) {
ans.push_back(str);
}
for (int i = ans.size() - 1; i >= 0; i--) {
if (i != ans.size() - 1) cout << " ";
cout << ans[i];
}
}


### 1010 一元多项式求导(25)

3 4 -5 2 6 1 -2 0

12 3 -10 1 6 0

#include <bits/stdc++.h>

using namespace std;
vector< pair<int, int> >ans;
int main() {
int x, y;
while(cin >> x >> y) {
if(y >= 1) {
ans.push_back({x * y, y - 1});
}
}
if(ans.size() == 0) cout << "0 0";
for(int i = 0; i < ans.size(); i++) {
if(i != 0) cout << " ";
cout << ans[i].first << " " << ans[i].second;
}
}


### 1011 A+B 和 C(15)

4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647

Case #1: false
Case #2: true
Case #3: true
Case #4: false

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) {
ll a, b, c;
cin >> a >> b >> c;
cout << "Case #" << i + 1 << ": ";
if(a + b > c) cout << "true" << endl;
else cout << "false" << endl;
}
}


### 1012 数字分类(20)

A_1 = 能被 5 整除的数字中所有偶数的和；
A_2 = 将被 5 除后余 1 的数字按给出顺序进行交错求和，即计算 n_1−n _2 +n_3−n _4 ⋯；
A_3= 被 5 除后余 2 的数字的个数；
A_4= 被 5 除后余 3 的数字的平均数，精确到小数点后 1 位；
A _5= 被 5 除后余 4 的数字中最大数字。

13 1 2 3 4 5 6 7 8 9 10 20 16 18

30 11 2 9.7 9

8 1 2 4 5 6 7 9 16

N 11 2 N 9

tips:一直是19/20，因为原先我的判断N的依据为是否a[i] = 0但是a[3] == 11 - 11,所以会被卡掉，不能这么判断

#include <bits/stdc++.h>
using namespace std;
double a[6];
bool flag[6];
int main() {
int n;
cin >> n;
int f = 1;
int cnt = 0;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
if(x % 5 == 0) {
if(x % 2 == 0) a[1] += x, flag[1] = 1;
}
else if(x % 5 == 1) {
a[2] += f * x;
f = -1 * f;
flag[2] = 1;
}
else if(x % 5 == 2) {
a[3]++;
flag[3] = 1;
}
else if(x % 5 == 3){
a[4] += x;
cnt++;
flag[4] = 1;
}
else {
a[5] = max((int)a[5], x);
flag[5] = 1;
}
}
if(cnt != 0)  a[4] /= cnt;
for(int i = 1; i <= 5; i++) {
if(i != 1) cout << " ";
if(flag[i] == 0) cout << 'N';
else if(i == 4) printf("%.1f", a[4]);
else cout << a[i];
}
}


### 1013 数素数(20)

5 27

11 13 17 19 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89
97 101 103

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;
bool isp[MAX];
int pri[MAX];
vector<int> ans;
void solve(int n, int m) {
isp[0] = isp[1] = 1;
int cnt = 1;
for(int i = 2; i < MAX; i++) {
if(isp[i] == 0) {
if(cnt > m) return;
if(cnt >= n) ans.push_back(i);
pri[cnt++] = i;
for(int j = 2 * i; j < MAX; j += i) {
isp[j] = 1;
}
}
}
}
int main() {
int n, m;
cin >> n >> m;
solve(n, m);
int cnt = 0;
for(int i = 0; i < ans.size(); i++) {
if(cnt != 0) cout << " ";
cout << ans[i];
cnt++;
if(cnt == 10) {
cnt = 0;
cout << endl;
}
}
}


### 1014 福尔摩斯的约会(20)

3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

THU 14:04

#include <bits/stdc++.h>
using namespace std;
string week[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int main() {
string a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b2;
char w = 'a', h = 'a';
int cnt1 = 0;
int pos = 0;
for(int i = 0; i < min(a1.size(), a2.size()); i++) {
if(a1[i] == a2[i]) {
if(a1[i] >= 'A' && a1[i] <= 'G') {
cnt1++;
if(cnt1 == 1) w = a1[i];
pos = i;
break;
}
}
}
for(int i = pos + 1; i < min(a1.size(), a2.size()); i++) {
if(a1[i] == a2[i]) {
if(a1[i] >= '0' && a1[i] <= '9' || a1[i] >= 'A' && a1[i] <= 'N') {
cnt1++;
if(cnt1 == 2) h = a1[i];
}
}
}
int hh = 0, mm = 0;
for(int i = 0; i < min(b1.size(), b2.size()); i++) {
if(b1[i] == b2[i] && (b1[i] >= 'a' && b1[i] <= 'z' || b1[i] >= 'A' && b1[i] <= 'Z')) {
mm = i;
break;
}
}
cout << week[w - 'A'] << " ";
if(h >= '0' && h <= '9') hh = h - '0';
else hh = h - 'A' + 10;
printf("%02d:%02d", hh, mm);
}


### 1015 德才论(25)

14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60

12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
struct stu{
string xue;
int de, cai;
int level;
int sum;
}a[MAX];
int main() {
int n, L, H;
cin >> n >> L >> H;
int cnt = 0;
for(int i = 0; i < n; i++) {
cin >> a[i].xue >> a[i].de >>a[i].cai;
if(a[i].de < L || a[i].cai < L) a[i].level = 100;
else {
cnt++;
if(a[i].de >= H && a[i].cai >= H) a[i].level = 0;
else if(a[i].de >= H) a[i].level = 1;
else if(a[i].de >= a[i].cai) a[i].level = 2;
else a[i].level = 3;
}
a[i].sum = a[i].de + a[i].cai;
}
sort(a, a + n, [](stu a, stu b) {
if(a.level != b.level) {
return a.level < b.level;
}
if(a.sum != b.sum) {
return a.sum > b.sum;
}
if(a.de != b.de) {
return a.de > b.de;
}
return a.xue < b.xue;
});
cout << cnt <<endl;
for(int i = 0; i < n; i++) {
if(a[i].level != 100) {
cout << a[i].xue << " " << a[i].de << " " << a[i].cai << endl;
}
}
}


### 1016 部分A+B(15)

3862767 6 13530293 3

399

3862767 1 13530293 8

0

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
string A, B;
int DA, DB, cnt0 = 0, cnt1 = 0;
cin >> A >> DA >> B >> DB;
for(int i = 0; i < A.size(); i++) {
if(A[i] - '0' == DA) cnt0++;
}
for(int i = 0; i < B.size(); i++) {
if(B[i] - '0' == DB) cnt1++;
}
ll ansA = 0, ansB = 0;
while(cnt0) {
ansA = ansA * 10 + DA;
cnt0--;
}
while(cnt1) {
ansB = ansB * 10 + DB;
cnt1--;
}
cout << ansA + ansB << endl;
}


### 1017 A除以B(20)

123456789050987654321 7

17636684150141093474 3

#include <bits/stdc++.h>

using namespace std;

int main() {
string A;
int b;
cin >> A >> b;
int tmp = 0, pos = 0;
vector<int> ans;
while (pos < A.size()) {
tmp = tmp * 10 + A[pos++] - '0';
ans.push_back(tmp / b);
tmp %= b;
}
int pos0 = 0;
while (pos0 < ans.size() && ans[pos0] == 0) pos0++;
if (ans.size() == pos0) cout << 0;
else {
for (int i = pos0; i < ans.size(); i++) cout << ans[i];
}
cout << " " << tmp;
}


### 1018 锤子剪刀布(20)

10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J

5 3 2
2 3 5
B B

#include <bits/stdc++.h>

using namespace std;

int ans1[4];
int ans2[4];
map<char, int> a;
map<char, int> b;

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char c, d;
cin >> c >> d;
if (a[c] == 0) a[c] = 0;
if (b[d] == 0) b[d] = 0;
if (c == d) {
ans1[2]++;
ans2[2]++;
} else if (c == 'C' && d == 'J' || c == 'J' && d == 'B' || c == 'B' && d == 'C') {
ans1[1]++;
ans2[3]++;
a[c]++;
} else {
ans1[3]++;
ans2[1]++;
b[d]++;
}
}
cout << ans1[1] << " " << ans1[2] << " " << ans1[3] << endl;
cout << ans2[1] << " " << ans2[2] << " " << ans2[3] << endl;
int max1 = -1, max2 = -1;
for (auto x: a) {
max1 = max(max1, x.second);
}
for (auto x: b) {
max2 = max(max2, x.second);
}
for (auto x: a) {
if (x.second == max1) {
cout << x.first << " ";
break;
}
}
for (auto x: b) {
if (x.second == max2) {
cout << x.first;
break;
}
}
}


### 1019 数字黑洞(20)

7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
7641 - 1467 = 6174
… …

6767

7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174

2222

2222 - 2222 = 0000

#include <bits/stdc++.h>

using namespace std;

int main() {
string str;
cin >> str;
str = string(4 - str.length(), '0') + str;
while (1) {
int a = 0, b = 0;
char ch[4];
for (int i = 0; i < 4; i++) {
ch[i] = str[i];
}
sort(ch, ch + 4);
for (int i = 0; i < 4; i++) {
b = b * 10 + ch[i] - '0';
}
for (int i = 3; i >= 0; i--) {
a = a * 10 + ch[i] - '0';
}
str = string(4 - to_string(a - b).length(), '0') + to_string(a - b);
printf("%04d - %04d = %04d\n", a, b, a - b);
if (str == "6174" || str == "0000") break;
}
}


### 1020 月饼(25)

3 20
18 15 10
75 72 45

94.50

#include <bits/stdc++.h>

using namespace std;
struct node {
double p;
double tot;
double price;
}a[1100];
int main() {
int n, tot;
cin >> n >> tot;
for(int i = 0; i < n; i++) {
cin >> a[i].tot;
}
for(int i = 0; i < n; i++) {
cin >> a[i].price;
a[i].p = a[i].price / a[i].tot;
}
sort(a, a + n, [](node a, node b) {
return a.p > b.p;
});
double ans = 0;
for(int i = 0; i < n; i++) {
tot -= min(tot, (int)a[i].tot);
ans += min(tot, (int)a[i].tot) * a[i].p;
if(tot == 0) break;
}
printf("%.2f\n", ans);
}


### 1021 个位数统计(15)

100311

0:2
1:3
3:1

#include <bits/stdc++.h>
using namespace std;
int a[11];
int main() {
string str;
cin >> str;
for(int i = 0; i < str.length(); i++) {
a[str[i] - '0']++;
}
for(int i = 0; i < 10; i++) {
if(a[i] != 0) cout << i << ":" << a[i] << endl;
}
}



### 1022 D进制的A+B(20)

123 456 8

1103

tips:条件为非负数，那就一定判断0

#include <bits/stdc++.h>

using namespace std;

int main() {
long long a, b, x;
cin >> a >> b >> x;
long long c = a + b;
long long tmp = 1;
vector<int> ans;
if (c == 0) {
cout << 0;
return 0;
}
while (c >= tmp) tmp = tmp * x;
tmp /= x;
while (1) {
ans.push_back(c / tmp);
if (tmp == 1) break;
c -= c / tmp * tmp;
tmp /= x;
}
for (auto x: ans) {
cout << x;
}
}


### 1023 组个最小数(20)

2 2 0 0 0 3 0 0 1 0

10015558

#include <bits/stdc++.h>

using namespace std;
int a[12];

int main() {
for (int i = 0; i < 10; i++) cin >> a[i];
int pos = 0;
for (int i = 1; i < 10; i++) {
if (a[i] != 0) {
pos = i;
break;
}
}
cout << pos;
a[pos]--;
for (int i = 0; i < 10; i++) {
cout << string(a[i], i + '0');
}
}


### 1024 科学计数法(20)

+1.23400E-03

0.00123400

-1.2E+10

-12000000000

tips：麻烦的题目，要冷静思考推出每种情况

string 初始化为“”，不要写别的了

string x2 = str.substr(3, i - 3);//开始位置， 长度
int y = stoi(str.substr(i + 1));//包括i+1以后的字符串

#include <bits/stdc++.h>

using namespace std;

int main() {
string str;
cin >> str;
char fu1 = str[0];
char x1 = str[1];
string x2 = "";
int i;
for (i = 3; i < str.size(); i++) {
if (str[i] == 'E') break;
x2 += str[i];
}
char fu2 = str[i + 1];
int y = 0;
for (int j = i + 2; j < str.size(); j++) {
y = y * 10 + str[j] - '0';
}
string ans = "";
if (fu1 == '-') ans += fu1;
if (fu2 == '+') {
ans += x1;
if (x2.length() > y) {
for (int i = 0; i < y; i++) {
ans += x2[i];
}
ans += '.';
for (int i = y; i < x2.length(); i++) ans += x2[i];
} else {
ans += x2 + string(y - x2.length(), '0');
}
} else {
ans += "0." + string(y - 1, '0') + x1 + x2;
}
cout << ans;
}


### 1025 反转链表(25)

00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218

00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e6 + 10;
struct node {
int data;
int next;
} a[MAX];

int main() {
int s, n, k;
cin >> s >> n >> k;
for (int i = 0; i < n; i++) {
int ne, ad, da;
cin >> ad >> da >> ne;
}
int pos = 0;
vector<node> ans;
vector<node> b;
while (s != -1) {
b.push_back({s, a[s].data, a[s].next});
pos++;
if (pos == k) {
pos = 0;
for (int i = k - 1; i >= 0; i--) {
ans.push_back(b[i]);
}
b.clear();
}
s = a[s].next;
}
for (int i = 0; i < b.size(); i++) {
ans.push_back(b[i]);
}
for (int i = 0; i < ans.size(); i++) {
if (i != ans.size() - 1) printf("%05d %d %05d\n", ans[i].ad, ans[i].data, ans[i + 1].ad);
else printf("%05d %d -1\n", ans[i].ad, ans[i].data);
}
}


### 1026 程序运行时间(15)

123 4577973

12:42:59

tips: int tmp = (c2 - c1 + 50) / 100;//四舍五入

#include <bits/stdc++.h>
using namespace std;
int main() {
int c1, c2;
cin >> c1 >> c2;
int tmp = (c2 - c1 + 50) / 100;//四舍五入
int h = tmp / 3600;
tmp %= 3600;
int m = tmp / 60;
int s = tmp % 60;
printf("%02d:%02d:%02d", h, m, s);
}


### 1027 打印沙漏(20)

*****
***
*
***
*****

19 *

*****
***
*
***
*****
2

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
char ch;
cin >> n >> ch;
int tmp = 0;
while (2 * tmp * tmp - 1 <= n) tmp++;
tmp--;
for (int i = tmp; i >= 1; i--) {
cout << string(tmp - i, ' ') << string(i * 2 - 1, ch) << endl;
}
for (int i = 2; i <= tmp; i++) {
cout << string(tmp - i, ' ') << string(i * 2 - 1, ch) << endl;
}
cout << n - (2 * tmp * tmp - 1) << endl;
}


### 1028 人口普查(20)

5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20

3 Tom John

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
int cnt = 0;
string d1 = "1814/09/06", d2 = "2014/09/06";
string minn = "2014/09/10", maxx = "1814/09/10";
string n1 = "", n2 = "";
for (int i = 0; i < n; i++) {
string name, day;
cin >> name >> day;
if (day >= d1 && day <= d2) {
cnt++;
if (day <= minn) {
minn = day;
n1 = name;
}
if (day >= maxx) {
maxx = day;
n2 = name;
}
}
}
if (cnt == 0) cout << cnt << endl;
else cout << cnt << " " << n1 << " " << n2 << endl;
}


### 1029 旧键盘(20)

7_This_is_a_test
_hs_s_a_es

7TI

tips：当类似于while(i < a && j < b){}一定要考虑i或者j单独一个没有到a或者b

#include <bits/stdc++.h>

using namespace std;

int main() {
string s, t;
cin >> s >> t;
vector<char> ans;
int i = 0, j = 0;
while (i < s.length() && j < t.length()) {
while (s[i] == t[j] && i < s.length() && j < t.length()) i++, j++;
while (s[i] != t[j] && i < s.length() && j < t.length()) {
if (islower(s[i])) s[i] += 'A' - 'a';
bool flag = 0;
for (auto x: ans) {
if (x == s[i]) flag = 1;
}
if (flag == 0) ans.push_back(s[i]);
i++;
}
}
while (i < s.length()) {
if (islower(s[i])) s[i] += 'A' - 'a';
bool flag = 0;
for (auto x: ans) {
if (x == s[i]) flag = 1;
}
if (flag == 0) ans.push_back(s[i]);
i++;
}
for (auto x: ans) cout << x;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
string s, t;
cin >> s >> t;
string ans;
for (int i = 0; i < s.length(); i++) {
if (ans.find(toupper(s[i])) == string::npos && t.find(s[i]) == string::npos &&
t.find(toupper(s[i])) == string::npos) {
ans += toupper(s[i]);
}
}
cout << ans;
}


### 1030 完美数列(25)

10 8
2 3 20 4 5 1 6 7 8 9

8

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
long long a[MAX];

int main() {
int n, p;
cin >> n >> p;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int ans = 0;
int pos = 0;
for (int i = 0; i < n; i++) {
while (pos < n && a[pos] <= a[i] * p) {
pos++;
}
ans = max(pos - i, ans);
}
cout << ans << endl;
}


### 1031 查验身份证(15)

Z：0 1 2 3 4 5 6 7 8 9 10
M：1 0 X 9 8 7 6 5 4 3 2

4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X

12010X198901011234
110108196711301866
37070419881216001X

2
320124198808240056
110108196711301862

All passed

#include <bits/stdc++.h>

using namespace std;
int a[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
int z[] = {1, 0, -1, 9, 8, 7, 6, 5, 4, 3, 2};
vector<string> ans;

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
bool flag = 0;
for (int i = 0; i < 17; i++) {
if (!isdigit(str[i])) flag = 1;
}
if (flag == 1) {
ans.push_back(str);
continue;
}
int res = 0;
for (int i = 0; i < 17; i++) {
res += (str[i] - '0') * a[i];
}
res %= 11;
if (z[res] == -1) {
if (str[17] == 'X');
else ans.push_back(str);
} else if (z[res] != str[17] - '0') ans.push_back(str);
}
if (ans.size() == 0) cout << "All passed";
else {
for (auto x: ans) {
cout << x << endl;
}
}
}


### 1032 挖掘机技术哪家强(20)

6
3 65
2 80
1 100
2 70
3 40
3 0

2 150

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
int a[MAX];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[x] += y;
}
int maxx = 0, pos = 1;//pos = 1,因为从一开始
for (int i = 1; i < MAX; i++) {
if (a[i] > maxx) {
maxx = a[i];
pos = i;
}
}
cout << pos << " " << maxx;
}


### 1033 旧键盘打字(20)

7+IE.
7_This_is_a_test.

_hs_s_a_tst

#include <bits/stdc++.h>

using namespace std;
bool a[320];
int main() {
string s, t;
getline(cin, s);
getline(cin, t);
for(int i = 0; i < s.length(); i++) {
if(s[i] == '+') {
for(int i = 0; i < 26; i++) a['A' + i] = 1;
}
a[toupper(s[i])] = 1;
a[tolower(s[i])] = 1;
}
for(int i = 0;i < t.length(); i++) {
if(a[t[i]] == 0) cout << t[i];
}
}


### 1034 有理数四则运算(20)

2/3 -4/2

2/3 + (-2) = (-1 1/3)
2/3 - (-2) = 2 2/3
2/3 * (-2) = (-1 1/3)
2/3 / (-2) = (-1/3)

5/3 0/6

1 2/3 + 0 = 1 2/3
1 2/3 - 0 = 1 2/3
1 2/3 * 0 = 0
1 2/3 / 0 = Inf

#include <bits/stdc++.h>

using namespace std;

int main() {
long long a[10], b[10];
scanf("%lld/%lld %lld/%lld", &a[1], &b[1], &a[2], &b[2]);
b[3] = b[1] * b[2], a[3] = a[1] * b[2] + a[2] * b[1];
b[4] = b[1] * b[2], a[4] = a[1] * b[2] - a[2] * b[1];
b[5] = b[1] * b[2], a[5] = a[1] * a[2];
b[6] = b[1] * a[2], a[6] = b[2] * a[1];
for (int i = 1; i <= 6; i++) {
int gcd = __gcd(a[i], b[i]);
a[i] /= gcd;
b[i] /= gcd;
}
string c[10];
for (int i = 1; i <= 6; i++) {
if (b[i] == 0) c[i] = "Inf";
else if (a[i] % b[i] == 0) c[i] = to_string(a[i] / b[i]);
else if (abs(a[i]) > abs(b[i]))
c[i] = to_string(a[i] / b[i]) + " " + to_string(abs(a[i] % b[i])) + "/" + to_string(abs(b[i]));
else {
if (b[i] < 0) b[i] = -b[i], a[i] = -a[i];
c[i] = to_string(a[i]) + "/" + to_string(b[i]);
}
}

for (int i = 1; i <= 6; i++) {
if (c[i][0] == '-') c[i] = "(" + c[i] + ")";
}
cout << c[1] << " + " << c[2] << " = " << c[3] << endl;
cout << c[1] << " - " << c[2] << " = " << c[4] << endl;
cout << c[1] << " * " << c[2] << " = " << c[5] << endl;
cout << c[1] << " / " << c[2] << " = " << c[6] << endl;
}


### 1035 插入与归并(25)

10
3 1 2 8 7 5 9 4 6 0
1 2 3 7 8 5 9 4 6 0

Insertion Sort
1 2 3 5 7 8 9 4 6 0

10
3 1 2 8 7 5 9 4 0 6
1 3 2 8 5 7 4 9 0 6

Merge Sort

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
int a[110];
int b[110];

bool fuhe(int n, int tmp) {
int c[110];
for (int i = 1; i <= n; i++)c[i] = a[i];
int j;
for (j = 0; j <= n; j += tmp) {
sort(c + j + 1, c + min(n + 1, j + tmp + 1));
}
for (int i = 1; i <= n; i++) {
if (c[i] != b[i]) return 0;
}
return 1;
}

int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
bool flag = 1;
int pos = 1;
while (pos + 1 <= n && b[pos] <= b[pos + 1]) pos++;
for (int i = pos + 1; i <= n; i++) {
if (a[i] != b[i]) flag = 0;
}
if (flag == 1) {
cout << "Insertion Sort\n";
sort(b + 1, b + pos + 2);
for (int i = 1; i <= n; i++) {
if (i != 1) cout << " ";
cout << b[i];
}
} else {
cout << "Merge Sort\n";
for (int i = 2; i <= n; i *= 2) {
if (fuhe(n, i)) {
int tmp = 2 * i;
int j;
for (j = 0; j <= n; j += tmp) {
sort(b + j + 1, b + min(n + 1, j + tmp + 1));
}
for (int i = 1; i <= n; i++) {
if (i != 1) cout << " ";
cout << b[i];
}
return 0;
}
}
}
}


### 1036 跟奥巴马一起编程(15)

10 a

aaaaaaaaaa
a a
a a
a a
aaaaaaaaaa

#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
char ch;
cin >> x >> ch;
cout << string(x, ch) << endl;
for(int i = 0; i < (x + 1)/ 2 - 2; i++) {
cout << ch << string(x - 2, ' ') << ch << endl;
}
cout << string(x, ch) << endl;
}



### 1037 在霍格沃茨找零钱(20)

10.16.27 14.1.28

3.2.1

14.1.28 10.16.27

-3.2.1

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll a[2][4];
ll ans[3];

int main() {
scanf("%lld.%lld.%lld %lld.%lld.%lld", &a[0][1], &a[0][2], &a[0][3], &a[1][1], &a[1][2], &a[1][3]);
for (int i = 0; i < 2; i++) {
ans[i] = a[i][1] * 17 * 29 + a[i][2] * 29 + a[i][3];
}
ll res = ans[1] - ans[0];
cout << res / (17 * 29) << "." << abs(res % (17 * 29) / 29) << "." << abs(res % 29);
}


### 1038 统计同成绩学生(20)

10
60 75 90 55 75 99 82 90 75 50
3 75 90 88

3 2 0

#include <bits/stdc++.h>

using namespace std;

int a[110];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
cout << a[x];
if (q != 0) cout << " ";
}
}


### 1039 到底买不买(20)

ppRYYGrrYBR2258
YrR8RrY

Yes 8

ppRYYGrrYB225
YrR8RrY

No 2

#include <bits/stdc++.h>

using namespace std;

map<char, int> a;
map<char, int> b;

int main() {
string s, t;
getline(cin, s);
getline(cin, t);
for (auto x: s) a[x]++;
for (auto x: t) b[x]++;
int cha = 0;
for (auto x: b) {
if (a.find(x.first) != a.end()) {
if (a[x.first] >= b[x.first]) {
} else {
cha += (b[x.first] - a[x.first]);
}
} else {
cha += b[x.first];
}
}
if (cha != 0) {
cout << "No " << cha;
} else {
cout << "Yes " << s.length() - t.length();
}
}


### 1040 有几个PAT(25)

APPAPT

2

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
const int mod = 1e9 + 7;
int p[MAX];
int t[MAX];

int main() {
string s;
cin >> s ;
int tmp1 = 0, tmp2 = 0;
for(int i = 0; i < s.length(); i++) {
if(s[i] == 'P') {
tmp1++;
}
p[i] = tmp1;
}
for(int i = s.length() - 1; i >= 0 ; i--) {
if(s[i] == 'T') {
tmp2++;
}
t[i] = tmp2;
}
long long ans = 0;
for(int i = 0; i < s.length(); i++) {
if(s[i] == 'A') {
ans = (ans + p[i] * t[i]) % mod;
}
}
cout << ans << endl;
}



### 1041 考试座位号(15)

4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4

3310120150912002 2
3310120150912119 1

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e3 + 10;
struct stu {
string xue;
int s;
} a[MAX];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string xue;
int s, t;
cin >> xue >> t >> s;
a[t].xue = xue, a[t].s = s;
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
cout << a[x].xue << " " << a[x].s << endl;
}
}


### 1042 字符统计(20)

#include <bits/stdc++.h>

using namespace std;
int a[320];

int main() {
string s;
getline(cin, s);
int maxx = 0;
for (int i = 0; i < s.length(); i++) {
if (isalpha(s[i])) {
a[tolower(s[i])]++;
maxx = max(maxx, a[tolower(s[i])]);
}
}
for (int i = 0; i < 255; i++) {
if (a[i] == maxx) {
cout << (char) i << " " << maxx << endl;
return 0;
}
}
}


### 1043 输出PATest(20)

redlesPayBestPATTopTeePHPereatitAPPT

PATestPATestPTetPTePePee

#include <bits/stdc++.h>

using namespace std;
int a[320];
string str = "PATest";

int main() {
string s;
getline(cin, s);
for (int i = 0; i < s.length(); i++) {
a[s[i]]++;
}
while (1) {
bool flag = 1;
for (int i = 0; i < str.length(); i++) {
if (a[str[i]] != 0) {
cout << str[i];
a[str[i]]--;
flag = 0;
}
}
if (flag == 1) break;
}
}



### 1044 火星数字(20)

4
29
5
elo nov
tam

hel mar
may
115
13

#include <bits/stdc++.h>

using namespace std;
string a1[13] = {"jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string a2[13] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};

int main() {
int n;
cin >> n;
getchar();
while (n--) {
string s;
getline(cin, s);
if (isdigit(s[0])) {
int x = stoi(s);
if (x >= 13 && x % 13 != 0)
cout << a2[x / 13 - 1] << " ";
if (x >= 13 && x % 13 == 0) {
cout << a2[x / 13 - 1];
}
if (x >= 1)
cout << a1[x % 13 - 1] << endl;
else cout << "tret" << endl;
} else {
map<string, int> aa;
for (int i = 0; i < 12; i++) {
aa.insert({a1[i], i + 1});
aa.insert({a2[i], (i + 1) * 13});
}
int ans = 0;
if (s.find(' ') != string::npos) {
int pos = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == ' ') {
pos = i;
break;
}
}
ans = aa[s.substr(0, pos)] + aa[s.substr(pos + 1, s.length() - pos - 1)];
} else {
ans = aa[s];
}
cout << ans << endl;
}
}
}


### 1045 快速排序(25)

1 的左边没有元素，右边的元素都比它大，所以它可能是主元；

5
1 3 2 4 5

3
1 4 5

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
const int INF = 1e9 + 7;
int a[MAX], b[MAX], c[MAX];

int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int maxx = 0, minn = INF;
for (int i = 1; i <= n; i++) {
b[i] = maxx;
maxx = max(maxx, a[i]);
}
for (int i = n; i >= 1; i--) {
c[i] = minn;
minn = min(minn, a[i]);
}
vector<int> ans;
for (int i = 1; i <= n; i++) {
if (b[i] < a[i] && c[i] > a[i]) {
ans.push_back(a[i]);
}
}
cout << ans.size() << endl;
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
if (i != 0)cout << " ";
cout << ans[i];
}
cout << endl;
}


### 1046 划拳(15)

5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15

1 2

#include <bits/stdc++.h>

using namespace std;

int main() {
int cnt1 = 0, cnt2 = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b2;
int tmp = a1 + b1;
if (a2 == tmp && b2 == tmp);
else if (a2 == tmp) cnt2++;
else if (b2 == tmp) cnt1++;
}
cout << cnt1 << " " << cnt2 << endl;
}


### 1047 编程团体赛(20)

6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61

11 176

#include <bits/stdc++.h>

using namespace std;

int ans[1100];

int main() {
int n;
cin >> n;
int maxx = 0;
while (n--) {
int a, b, c;
scanf("%d-%d %d", &a, &b, &c);
ans[a] += c;
maxx = max(maxx, ans[a]);
}
for (int i = 1; i <= 1000; i++) {
if (ans[i] == maxx) {
cout << i << " " << ans[i] << endl;
}
}
}


### 1048 数字加密(20)

1234567 368782971

3695Q8118

#include <bits/stdc++.h>

using namespace std;

int main() {
string a, b;
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int lena = a.length(), lenb = b.length();
if (lena > lenb)
b += string(lena - lenb, '0');
else
a += string(lenb - lena, '0');
string ans = "";
for (int i = 0; i < b.size(); i++) {
if (i % 2 == 0) {
int tmp = b[i] - '0' + a[i] - '0';
tmp %= 13;
if (tmp == 10) ans += 'J';
else if (tmp == 11) ans += 'Q';
else if (tmp == 12) ans += 'K';
else ans += to_string(tmp);
} else {
int tmp = b[i] - a[i];
if (tmp < 0) tmp += 10;
ans += to_string(tmp);
}
}
reverse(ans.begin(), ans.end());
cout << ans;
}


### 1049 数列的片段和(20)

4
0.1 0.2 0.3 0.4

5.00

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
long double a[MAX];
long double sum[MAX];

int main() {
int n;
cin >> n;
long double ans = 0;
sum[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i] * i;
ans += sum[i];
}
printf("%.2llf\n", ans);
}


### 1050 螺旋矩阵(25)

12
37 76 20 98 76 42 53 95 60 81 58 93

98 95 93
42 37 81
53 20 76
58 60 76

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e4 + 10;
int g[MAX][MAX];
int a[MAX * MAX];

int main() {
int N;
cin >> N;
for (int i = 1; i <= N; i++) cin >> a[i];
sort(a + 1, a + 1 + N, [](int a, int b) {
return a > b;
});
int n = sqrt(N), m;
for (n = sqrt((double) N); n >= 1; n--) {
if (N % n == 0) {
m = N / n;
break;
}
}
int l = 1, r = n;
int h = 1, w = m;
int pos = 1;
while (l < r && h < w) {
for (int i = l; i <= r; i++) {
g[h][i] = a[pos++];
}
for (int i = h + 1; i <= w; i++) {
g[i][r] = a[pos++];
}
for (int i = r - 1; i >= l; i--) {
g[w][i] = a[pos++];
}
for (int i = w - 1; i >= h + 1; i--) {
g[i][l] = a[pos++];
}
l++, r--;
h++, w--;
}
if (pos != N + 1) {
for (int i = h; i <= w; i++) {
g[i][l] = a[pos++];
}
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (j != 1) cout << " ";
cout << g[i][j];
}
cout << endl;
}
}


### 1051 复数乘法(15)

2.3 3.5 5.2 0.4

-8.68-8.23i

#include <bits/stdc++.h>
using namespace std;
int main() {
double r1, r2, p1, p2;
cin >> r1 >> p1 >> r2 >> p2;
double a1 = r1 * cos(p1), b1 = r1 * sin(p1);
double a2 = r2 * cos(p2), b2 = r2 * sin(p2);
double a = a1 * a2 - b1 * b2;
double b = a1 * b2 + a2 * b1;
if(fabs(b - 0.0) < 1e-3) printf("%.2f+0.00i", a);
else if(fabs(a - 0.0) < 1e-3) {
if(b > 0) printf("0.00+%.2fi", b);
else printf("0.00%.2fi", b);
}
else if (b == 0) printf("%.2f", a);
else if(b > 0) printf("%.2f+%.2fi", a, b);
else printf("%.2f%.2fi", a, b);
}


### 1052 卖个萌(20)

[左手]([左眼][口][右眼])[右手]

[╮][╭][o][~][/~] [<][>]
[╯][╰][^][-][=][>][<][@][⊙]
[Д][▽][_][ε][^] …
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3

╮(╯▽╰)╭
<(@Д=)/~
o(ε)o
Are you kidding me? @/@

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
int id[4];
string a[4][MAX];
string s[4];

void solve(int idx) {
int pos = 0;
for (int i = 0; i < s[idx].length(); i++) {
if (s[idx][i] == '[') {
string str = "";
i++;
while (s[idx][i] != ']' && i < s[idx].length()) {
str += s[idx][i];
i++;
}
if (s[idx][i] == ']') {
a[idx][pos++] = str;
id[idx] = pos - 1;
}
}
}
}

int main() {
getline(cin, s[0]);
getline(cin, s[1]);
getline(cin, s[2]);
for (int i = 0; i < 3; i++) {
solve(i);
}
int k;
cin >> k;
int b[6];
while (k--) {
for (int i = 0; i < 5; i++) cin >> b[i], b[i]--;
bool flag = 0;
for (int i = 0; i < 5; i++) if (b[i] < 0) flag = 1;
if (flag || b[0] > id[0] || b[4] > id[0] || b[1] > id[1] || b[3] > id[1] || b[2] > id[2]) {
cout << "Are you kidding me? @\\/@\n";
continue;
}
cout << a[0][b[0]] << "(" << a[1][b[1]] << a[2][b[2]] << a[1][b[3]] << ")" << a[0][b[4]] << endl;
}
}


### 1053 住房空置率(20)

K E_1 E_2 … E_K其中 K 为观察的天数，E_i 为第 i 天的用电量。

#include <bits/stdc++.h>

using namespace std;

int main() {
int n, d;
double e;
cin >> n >> e >> d;
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
int k, cnt = 0;
cin >> k;
for (int j = 0; j < k; j++) {
double x;
cin >> x;
if (x < e) cnt++;
}
if (cnt > k / 2) cnt1++;
if (cnt > k / 2 && k > d) cnt2++;
}
printf("%.1f%% %.1f%%\n", (cnt1 - cnt2) * 100.0 / n, cnt2 * 100.0 / n);
}


### 1054 求平均值(20)

7
5 -3.2 aaa 9999 2.3.4 7.123 2.35

ERROR: aaa is not a legal number
ERROR: 9999 is not a legal number
ERROR: 2.3.4 is not a legal number
ERROR: 7.123 is not a legal number
The average of 3 numbers is 1.38

2
aaa -9999

ERROR: aaa is not a legal number
ERROR: -9999 is not a legal number
The average of 0 numbers is Undefined

#include <bits/stdc++.h>

using namespace std;

bool is(double &tmp, string s) {
for (int i = 0; i < s.length(); i++) {
if (i == 0 && !isdigit(s[i]) && s[i] != '-') return 0;
if (i != 0 && !isdigit(s[i]) && s[i] != '.') return 0;
}
int pos = -1;
int cnt = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '.') {
pos = i;
cnt++;
}
}
if (cnt > 1) return 0;
//.0 或者 1. 都算
//if (pos == 0 || pos == s.length() - 1) return 0;
if (pos != -1) {
if (pos + 3 < s.length()) return 0;
}
double tmp1 = 0, tmp2 = 0;
if (pos == -1) pos = s.length();
if (s[0] == '-') {
for (int i = 1; i < pos; i++) {
tmp1 = tmp1 * 10 + s[i] - '0';
}
} else {
for (int i = 0; i < pos; i++) {
tmp1 = tmp1 * 10 + s[i] - '0';
}
}
for (int i = s.length() - 1; i >= pos + 1; i--) {
tmp2 = tmp2 * 0.1 + s[i] - '0';
}
tmp = tmp1 + tmp2 * 0.1;
if (s[0] == '-') tmp = -tmp;
if (fabs(tmp) > 1000) return 0;
return 1;
}

int main() {
int n;
cin >> n;
double ans = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
double tmp = 0;
if (is(tmp, s)) {
ans += tmp;
cnt++;
} else {
cout << "ERROR: " << s << " is not a legal number" << endl;
}
}
if (cnt == 0) {
cout << "The average of 0 numbers is Undefined";
} else if (cnt == 1) {
cout << "The average of " << cnt << " number is ";
printf("%.2f\n", ans / cnt);
} else {
cout << "The average of " << cnt << " numbers is ";
printf("%.2f\n", ans / cnt);
}
}


### 1055 集体照(25)

10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159

Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John

#include <bits/stdc++.h>

using namespace std;

struct peo {
int h;
string name;
} a[11000];
peo g[22][11000];

int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].name >> a[i].h;
}
sort(a + 1, a + n + 1, [](peo a, peo b) {
if (a.h != b.h) return a.h < b.h;
return a.name > b.name;
});
int m = n / k;
int pos = 1;
for (int i = 1; i <= k - 1; i++) {
int cnt1 = 1, cnt2 = m;
for (int j = 1; j <= m; j++) {
if (j % 2 == 1) {
g[i][cnt2--] = a[pos++];
} else {
g[i][cnt1++] = a[pos++];
}
}
}
int m2 = n - pos + 1;
int cnt1 = 1, cnt2 = m2;
for (int j = 1; j <= m2; j++) {
if (j % 2 == 1) {
g[k][cnt2--] = a[pos++];
} else {
g[k][cnt1++] = a[pos++];
}
}
if (m2 % 2 == 0) {
for (int j = m2; j >= 1; j--) {
if (j != m2) cout << " ";
cout << g[k][j].name;
}
} else
for (int j = 1; j <= m2; j++) {
if (j != 1) cout << " ";
cout << g[k][j].name;
}
cout << endl;
for (int i = k - 1; i >= 1; i--) {
if (m % 2 == 0) {
for (int j = m; j >= 1; j--) {
if (j != m) cout << " ";
cout << g[i][j].name;
}
}
for (int j = 1; j <= m; j++) {
if (j != 1) cout << " ";
cout << g[i][j].name;
}
cout << endl;
}
}


### 1056 组合数的和(15)

3 2 8 5

330

#include <bits/stdc++.h>

using namespace std;
int a[11];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
ans += a[i] * 10 + a[j];
}
}
cout << ans << endl;
}


### 1057 数零壹(20)

PAT (Basic)

3 4

#include <bits/stdc++.h>

using namespace std;

int main() {
string s;
getline(cin, s);
int ans = 0;
for(int  i= 0; i < s.length(); i++) {
if(isalpha(s[i]))
ans += tolower(s[i]) - 'a' + 1;
}
int cnt0 = 0, cnt1 = 0;
while(ans) {
if(ans % 2 == 0) cnt0++;
else cnt1++;
ans /= 2;
}
cout << cnt0 << " " << cnt1;
}


### 1058 选择题(20)

3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)

3
6
5
2 2 3 4

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e3 + 10;
int v[MAX];
int num[MAX];
map<char, int> ans[MAX];
int wrong[MAX];

int solve(string str) {
int que = 0;
int res = 0;
for (int j = 0; j < str.length(); j++) {
if (str[j] == '(') {
set<char> set1;
set<char> set2;
j++;
while (str[j] != ')') {
if (isalpha(str[j])) {
if (ans[que][str[j]] == 1)
set1.insert(str[j]);
set2.insert(str[j]);
}
j++;
}
if (set1.size() != set2.size() || set1.size() != num[que]) {
wrong[que]++;
} else {
res += v[que];
}
que++;
}
}
return res;
}

int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> v[i] >> x >> num[i];
for (int j = 0; j < num[i]; j++) {
char ch;
cin >> ch;
ans[i].insert({ch, 1});
}
}
getchar();
for (int i = 0; i < n; i++) {
string str;
getline(cin, str);
int tmp = solve(str);
cout << tmp << endl;
}
int maxx = 0;
for (int i = 0; i < m; i++) {
maxx = max(maxx, wrong[i]);
}
if (maxx != 0) {
cout << maxx;
for (int i = 0; i < m; i++) {
if (wrong[i] == maxx) {
cout << " " << i + 1;
}
}
} else {
cout << "Too simple" << endl;
}
}


### 1059 C语言竞赛(20)

C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩，颁奖规则也就制定得很滑稽：

0、冠军将赢得一份“神秘大奖”（比如很巨大的一本学生研究论文集……）。
1、排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶！
2、其他人将得到巧克力。

6
1111
6666
8888
1234
5555
0001
6
8888
0001
1111
2222
8888
2222

8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?

#include <bits/stdc++.h>

using namespace std;
set<string> ans;
map<string, int> num;
set<string> have;

bool isp(int x) {
if (x <= 1) return 0;
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) return 0;
}
return 1;
}

int main() {
int n;
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
string s;
cin >> s;
ans.insert(s);
if (i == 0) num.insert({s, 0});
else if (isp(i + 1)) num.insert({s, 1});
else num.insert({s, 2});
}
int k;
cin >> k;
getchar();
for (int i = 0; i < k; i++) {
string s;
cin >> s;
cout << s << ": ";
if (ans.find(s) == ans.end()) cout << "Are you kidding?" << endl;
else if (have.find(s) != have.end()) cout << "Checked" << endl;
else if (num[s] == 0) {
cout << "Mystery Award" << endl;
} else if (num[s] == 1) {
cout << "Minion" << endl;
} else if (num[s] == 2) {
cout << "Chocolate" << endl;
}
have.insert(s);
}
}


### 1060 爱丁顿数(25)

10
6 7 6 9 3 10 8 2 7 8

6

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e5 + 10;
int a[MAX];
int main() {
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a+ 1 + n,[](int a, int b) {
return a > b;
});
int maxx = -1;
for(int i = 1; i <= n; i++) {
maxx = max(maxx, min(i, a[i] - 1));
}
cout << maxx;
}


### 1061 判断题(15)

3 6
2 1 3 3 4 5
0 0 1 0 1 1
0 1 1 0 0 1
1 0 1 0 1 0
1 1 0 0 1 1

13
11
12

#include <bits/stdc++.h>

using namespace std;
int a[110];
int b[110];

int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
while (n--) {
int ans = 0;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
if (x == b[i]) ans += a[i];
}
cout << ans << endl;
}
}


### 1062 最简分数(20)

7/18 13/20 12

5/12 7/12

#include <bits/stdc++.h>

using namespace std;
int n[3], m[3];

int main() {
int k;
scanf("%d/%d %d/%d %d", &n[1], &m[1], &n[2], &m[2], &k);
if (n[1] > n[2]) {
swap(n[1], n[2]);
swap(m[1], m[2]);
}
vector<string> ans;
int x = 0;
while (x * m[1] <= n[1] * k) x++;
while (x * m[1] > n[1] * k && n[2] * k > m[2] * x) {
if (__gcd(x, k) == 1) {
string s = to_string(x) + '/' + to_string(k);
ans.push_back(s);
}
x++;
}
for (int i = 0; i < ans.size(); i++) {
if (i != 0) cout << " ";
cout << ans[i];
}
}


### 1063 计算谱半径(20)

5
0 1
2 0
-1 0
3 3
0 -3

4.24

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
double ans = 0;
cin >> n;
while (n--) {
double x, y;
cin >> x >> y;
ans = max(ans, sqrt(x * x + y * y));
}
printf("%.2f\n", ans);
}


### 1064 朋友数(20)

8
123 899 51 998 27 33 36 12

4
3 6 9 26

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
set<int> ans;
while (n--) {
string s;
cin >> s;
int res = 0;
for (int i = 0; i < s.length(); i++) {
res = res + s[i] - '0';
}
ans.insert(res);
}
cout << ans.size() << endl;
int i = 0;
for (auto x: ans) {
if (i != 0) cout << " ";
cout << x;
i++;
}
}


### 1065 单身狗(25)

“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人，以便给予特殊关爱。

3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333

5
10000 23333 44444 55555 88888

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e5 + 10;
map<string, string> ans;

int main() {
int n;
cin >> n;
getchar();
while (n--) {
string a, b;
cin >> a >> b;
ans.insert({a, b});
ans.insert({b, a});
}
set<string> have;
int q;
cin >> q;
while (q--) {
string a;
cin >> a;
have.insert(a);
}
vector<string> res;
for (string x: have) {
// cout << ans[x] << endl;
if (have.find(ans[x]) != have.end());
else res.push_back(x);
}
cout << res.size() << endl;
for (int i = 0; i < res.size(); i++) {
if (i != 0) cout << " ";
cout << res[i];
}
}


### 1066 图像过滤(15)

3 5 100 150 0
3 189 254 101 119
150 233 151 99 100
88 123 149 0 255

003 189 254 000 000
000 233 151 099 000
088 000 000 000 255

#include <bits/stdc++.h>

using namespace std;

int main() {
int n, m, a, b, s;
cin >> n >> m >> a >> b >> s;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int x;
scanf("%d", &x);//居然换成cin会T
if (j != 0) cout << " ";
if (x >= a && x <= b) {
printf("%03d", s);
} else printf("%03d", x);
if (j == m - 1) cout << endl;
}
}
}


### 1067 试密码(20)

Correct%pw 3
correct%pw
Correct@PW
Correct%pw

Account locked

cool@gplt 3
coolman@gplt
cool@gplt
try again

Welcome in

#include <bits/stdc++.h>

using namespace std;

int main() {
string ans;
int n;
cin >> ans >> n;
getchar();
string str;
bool flag = 0;
while (getline(cin, str) && str != "#") {
n--;
if (flag) continue;
if (n >= 0 && str == ans) {
cout << "Welcome in" << endl;
flag = 1;

} else {
if (n >= 0 && str != ans) {
cout << "Wrong password: " << str << endl;
}
if (n == 0) {
cout << "Account locked" << endl;
flag = 1;
}
}
}
}


### 1068 万绿丛中一点红(20)

8 6 200
0 0 0 0 0 0 0 0
65280 65280 65280 16711479 65280 65280 65280 65280
16711479 65280 65280 65280 16711680 65280 65280 65280
65280 65280 65280 65280 65280 65280 165280 165280
65280 65280 16777015 65280 65280 165280 65480 165280
16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215

(5, 3): 16711680

4 5 2
0 0 0 0
0 0 3 0
0 0 0 0
0 5 0 0
0 0 0 0

Not Unique

3 3 5
1 2 3
3 4 5
5 6 7

Not Exist

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e3 + 100;
int g[MAX][MAX];
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 1, -1, -1, 1, 0, 0};
map<int, int> aa;

int main() {
int n, m, cha;
cin >> m >> n >> cha;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> g[i][j];
aa[g[i][j]]++;
}
}
int cnt = 0;
pair<int, int> ans;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (aa[g[i][j]] != 1) continue;
bool flag = 1;
for (int k = 0; k < 8; k++) {
if (i + dx[k] >= 0 && i + dx[k] <= n && j + dy[k] >= 0 && j + dy[k] <= m)
if (fabs(g[i][j] - g[i + dx[k]][j + dy[k]]) <= cha) {
flag = 0;
}
}
if (flag == 1) {
cnt++;
ans = {i, j};
}
}
}
if (cnt == 0) cout << "Not Exist" << endl;
else if (cnt == 1) cout << "(" << ans.second << ", " << ans.first << "): " << g[ans.first][ans.second] << endl;
else cout << "Not Unique" << endl;
}


### 1069 微博转发抽奖(20)

9 3 2
Imgonnawin!
PickMe
PickMe
LookHere
Imgonnawin!
TryAgainAgain
TryAgainAgain
Imgonnawin!
TryAgainAgain

PickMe
Imgonnawin!
TryAgainAgain

2 3 5
Imgonnawin!
PickMe

Keep going…

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e3 + 100;
string s[MAX];
int main() {
int m, n, id;
cin >> m >> n >> id;
getchar();
for(int i = 1;i  <= m; i++) {
getline(cin, s[i]);
}
if(id > m) cout << "Keep going..." << endl;
else {
set<string> have;
for(int i = id; i <= m; i+=n) {
if(have.find(s[i]) == have.end()) {
cout << s[i] << endl;
}
else {
while (have.find(s[i]) != have.end() && i <= m) i++;
if(i <= m) cout << s[i] << endl;
}
have.insert(s[i]);
}
}
}


### 1070 结绳(25)

8
10 15 12 3 4 13 1 15

14

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e4 + 10;
double a[MAX];

int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
double ans = a[1];
for (int i = 2; i <= n; i++) {
ans = ans / 2 + a[i] / 2;
}
int res = floor(ans);
printf("%d\n", res);
}


### 1071 小赌怡情(15)

n1 b t n2

100 4
8 0 100 2
3 1 50 1
5 1 200 6
7 0 200 8

Win 100! Total = 200.
Lose 50. Total = 150.
Not enough tokens. Total = 150.
Not enough tokens. Total = 150.

100 4
8 0 100 2
3 1 200 1
5 1 200 6
7 0 200 8

Win 100! Total = 200.
Lose 200. Total = 0.
Game Over.

#include <bits/stdc++.h>

using namespace std;

int main() {
int tot, k;
cin >> tot >> k;
while (k--) {
int n1, n2, b, t;
cin >> n1 >> b >> t >> n2;
if (t > tot) printf("Not enough tokens.  Total = %d.\n", tot);
else {
if (n1 < n2 && b == 1 || n1 > n2 && b == 0) {
tot += t;
printf("Win %d!  Total = %d.\n", t, tot);
} else {
tot -= t;
printf("Lose %d.  Total = %d.\n", t, tot);
}
}
if (tot == 0) {
printf("Game Over.");
return 0;
}
}
}


### 1072 开学寄语(20)

4 2
2333 6666
CYLL 3 1234 2345 3456
U 4 9966 6666 8888 6666
GG 2 2333 7777
JJ 3 0012 6666 2333

U: 6666 6666
GG: 2333
JJ: 6666 2333
3 5

#include <bits/stdc++.h>

using namespace std;

int main() {
int n, m;
cin >> n >> m;
set<string> have;
for (int i = 0; i < m; i++) {
string s;
cin >> s;
have.insert(s);
}
int cnt0 = 0, cnt1 = 0;
while (n--) {
string s;
int k;
cin >> s >> k;
vector<string> cha;
for (int i = 0; i < k; i++) {
string s;
cin >> s;
if (have.find(s) != have.end()) {
cha.push_back(s);
}
}
if (cha.size() != 0) {
cnt0++;
cnt1 += cha.size();
cout << s << ": ";
for (int i = 0; i < cha.size(); i++) {
if (i != 0) cout << " ";
cout << cha[i];
}
cout << endl;
}
}
cout << cnt0 << " " << cnt1 << endl;
}


### 1073 多选题常见计分法(20)

3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

2 2
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)

5.0
5.0
Too simple

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e2 + 10;
set<char> ans[MAX];
int anscnt[MAX];
double v[MAX];
map<string, int> mp;

int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> v[i] >> x >> anscnt[i];
for (int j = 0; j < anscnt[i]; j++) {
char ch;
cin >> ch;
ans[i].insert(ch);
}
}
for (int i = 0; i < n; i++) {
double res = 0;
getchar();
for (int j = 0; j < m; j++) {
char ch;
int x;
cin >> ch >> x;
set<char> xuan;
bool flag = 1;
for (int k = 0; k < x; k++) {
cin >> ch;
if (ans[j].find(ch) == ans[j].end()) flag = 0;
xuan.insert(ch);
}
cin >> ch;
res += 0;
for (int i = 0; i < 5; i++) {
char ch = (char) (i + 'a');
if (xuan.find(ch) != xuan.end() && ans[j].find(ch) == ans[j].end() ||
xuan.find(ch) == xuan.end() && ans[j].find(ch) != ans[j].end()) {
string s = "";
s += to_string(j + 1) + '-' + ch;
mp[s]++;
}
}
if (flag != 0) {
if (xuan.size() < anscnt[j]) res += (v[j] / 2);
else res += v[j];
}
}
printf("%.1f\n", res);
}
if (mp.size() == 0) {
cout << "Too simple\n";
}
int maxx = -1;
for (auto x: mp) {
maxx = max(maxx, x.second);
}
for (auto x: mp) {
if (x.second == maxx) {
cout << x.second << " " << x.first << endl;
}
maxx = max(maxx, x.second);
}
}


### 1074 宇宙无敌加法器(20)

30527
06203
415

7201

#include <bits/stdc++.h>

using namespace std;

int main() {
string a, s1, s2;
cin >> a >> s1 >> s2;
reverse(a.begin(), a.end());
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
int maxx = max(max(s1.size(), s2.size()), a.size()) + 1;
a += string(maxx - a.length(), '0');
s1 += string(maxx - s1.length(), '0');
s2 += string(maxx - s2.length(), '0');
string ans = "";
int tmp = 0;
for (int i = 0; i < maxx; i++) {
int tmp1 = s1[i] - '0';
int tmp2 = s2[i] - '0';
int jin = a[i] - '0';
if (jin == 0) jin = 10;
tmp += tmp1 + tmp2;
ans += to_string(tmp % jin);
tmp /= jin;
}
reverse(ans.begin(), ans.end());
int pos = 0;
while (ans[pos] == '0' && pos + 1 < ans.size()) pos++;
while (pos < ans.size()) {
cout << ans[pos++];
}
}


### 1075 链表元素分类(25)

00100 9 10
23333 10 27777
00000 0 99999
00100 18 12309
68237 -6 23333
33218 -4 00000
48652 -2 -1
99999 5 68237
27777 11 48652
12309 7 33218

33218 -4 68237
68237 -6 48652
48652 -2 12309
12309 7 00000
00000 0 99999
99999 5 23333
23333 10 00100
00100 18 27777
27777 11 -1

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
struct node {
int data;
int next;
} a[MAX], b[MAX];

int main() {
int s, n, k;
cin >> s >> n >> k;
for (int i = 0; i < n; i++) {
}
int pos = 0;
int ss = s;
while (ss != -1) {
if (a[ss].data < 0) {
b[pos++] = a[ss];
}
ss = a[ss].next;
}
ss = s;
while (ss != -1) {
if (a[ss].data >= 0 && a[ss].data <= k) {
b[pos++] = a[ss];
}
ss = a[ss].next;
}
ss = s;
while (ss != -1) {
if (a[ss].data > k) {
b[pos++] = a[ss];
}
ss = a[ss].next;
}
for (int i = 0; i < pos; i++) {
if (i != pos - 1)
printf("%05d %d %05d\n", b[i].add, b[i].data, b[i + 1].add);
else
printf("%05d %d -1\n", b[i].add, b[i].data);
}
}


### 1076 Wifi密码(15)

8
A-T B-F C-F D-F
C-T B-F A-F D-F
A-F D-F C-F B-T
B-T A-F C-F D-F
B-F D-T A-F C-F
A-T C-F B-F D-F
D-T B-F C-F A-F
C-T A-F B-F D-F

13224143

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
while (n--) {
char a, b, c;
for (int i = 0; i < 4; i++) {
cin >> a >> b >> c;
if (c == 'T') {
cout << a - 'A' + 1;
}
}
}
}


### 1077 互评成绩计算(20)

+G_2 )/2，最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算每个组的互评成绩。

6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29

42
33
41
31
37
39

#include <bits/stdc++.h>

using namespace std;

int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int g1;
cin >> g1;
int g2 = 0;
int cnt = 0;
int maxx = -1, minn = 110;
for (int j = 0; j < n - 1; j++) {
int x;
cin >> x;
if (x < 0 || x > m) continue;
g2 += x;
maxx = max(maxx, x);
minn = min(minn, x);
cnt++;
}
g2 = (g2 - maxx - minn) / (cnt - 2);
cout << (g1 + g2 + 1) / 2 << endl;
}
}


### 1078 字符串压缩与解压(20)

C
TTTTThhiiiis isssss a tesssst CAaaa as

5T2h4is i5s a3 te4st CA3a as

D
5T2h4is i5s a3 te4st CA3a as10Z

TTTTThhiiiis isssss a tesssst CAaaa asZZZZZZZZZZ

#include <bits/stdc++.h>

using namespace std;

int main() {
string s1, s2;
getline(cin, s1);
getline(cin, s2);
if (s1 == "C") {
int pos = 0, cnt = 0;
while (pos < s2.length()) {
if (s2[pos] == s2[pos + 1] && pos + 1 < s2.length()) {
while (s2[pos] == s2[pos + 1] && pos + 1 < s2.length()) {
pos++;
cnt++;
}
} else {
if (cnt == 0) cout << s2[pos];
else cout << (cnt + 1) << s2[pos];
cnt = 0;
pos++;
}
}
} else if (s1 == "D") {
int pos = 0;
while (pos < s2.length()) {
if (isdigit(s2[pos])) {
int tmp = 0;
while (isdigit(s2[pos]) && pos < s2.length()) {
tmp = tmp * 10 + s2[pos] - '0';
pos++;
}
cout << string(tmp, s2[pos]);
pos++;
} else {
cout << s2[pos];
pos++;
}
}
}
}


### 1079 延迟的回文数(20)

A + B = C

97152

97152 + 25179 = 122331
122331 + 133221 = 255552
255552 is a palindromic number.

196

196 + 691 = 887
887 + 788 = 1675
1675 + 5761 = 7436
7436 + 6347 = 13783
13783 + 38731 = 52514
52514 + 41525 = 94039
94039 + 93049 = 187088
187088 + 880781 = 1067869
1067869 + 9687601 = 10755470
10755470 + 07455701 = 18211171

#include <bits/stdc++.h>

using namespace std;

int main() {
string s1, s2;
cin >> s1;
//初始特判
string t = s1;
reverse(t.begin(), t.end());
if (s1 == t) {
cout << s1 << " is a palindromic number." << endl;
return 0;
}
int cnt = 0;
while (1) {
s2 = s1;
reverse(s1.begin(), s1.end());
int tmp = 0;
string s = "";
for (int i = s1.length() - 1; i >= 0; i--) {
tmp = tmp + s1[i] - '0' + s2[i] - '0';
s += to_string(tmp % 10);
tmp /= 10;
}
s += to_string(tmp);
reverse(s.begin(), s.end());
int pos0 = 0;
while (pos0 + 1 < s.length() && s[pos0] == '0') {
pos0++;
}
s = s.substr(pos0);
cnt++;
if (cnt > 10) {
cout << "Not found in 10 iterations." << endl;
break;
} else {
string t = s;
reverse(t.begin(), t.end());
cout << s2 << " + " << s1 << " = " << s << endl;
s1 = s;
if (s == t) {
cout << s << " is a palindromic number." << endl;
break;
}
}
}
}


### 1080 MOOC期终成绩(25)

mid−term ；第三块包含 N 个期末考试成绩 G final 。每个成绩占一行，格式为：学生学号 分数。其中学生学号为不超过20个字符的英文字母和数字；分数是非负整数（编程总分最高为900分，期中和期末的最高分为100分）。

6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81

missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84

#include <bits/stdc++.h>

using namespace std;
const int MAX = 3e4 + 10;
struct stu {
int tot, fin, mid, nor;
string xue;
} a[MAX];
map<string, int> mp;

int main() {
int p, m, n;
cin >> p >> m >> n;
int cnt = 1;
for (int i = 0; i < p; i++) {
string xue;
int nor;
cin >> xue >> nor;
int pos = 0;
if (mp[xue] == 0) {
mp[xue] = cnt;
pos = cnt;
cnt++;
a[pos].tot = a[pos].mid = a[pos].nor = a[pos].fin = -1;
} else {
pos = mp[xue];
}
a[pos].xue = xue;
a[pos].nor = nor;
}
for (int i = 0; i < m; i++) {
string xue;
int mid;
cin >> xue >> mid;
int pos = 0;
if (mp[xue] == 0) {
mp[xue] = cnt;
pos = cnt;
cnt++;
a[pos].tot = a[pos].mid = a[pos].nor = a[pos].fin = -1;
} else {
pos = mp[xue];
}
a[pos].xue = xue;
a[pos].mid = mid;
}
for (int i = 0; i < n; i++) {
string xue;
int fin;
cin >> xue >> fin;
int pos = 0;
if (mp[xue] == 0) {
mp[xue] = cnt;
pos = cnt;
cnt++;
a[pos].tot = a[pos].mid = a[pos].nor = a[pos].fin = -1;
} else {
pos = mp[xue];
}
a[pos].xue = xue;
a[pos].fin = fin;
}
for (int i = 1; i < cnt; i++) {
if (a[i].mid > a[i].fin) {
a[i].tot = (int) (a[i].mid * 0.4 + a[i].fin * 0.6 + 0.5);
} else {
a[i].tot = a[i].fin;
}
}
sort(a + 1, a + cnt, [](stu a, stu b) {
if (a.tot != b.tot) return a.tot > b.tot;
return a.xue < b.xue;
});
for (int i = 1; i < cnt; i++) {
if (a[i].nor < 200 || a[i].tot < 60) continue;
cout << a[i].xue << " " << a[i].nor << " " << a[i].mid << " " << a[i].fin << " " << a[i].tot << endl;
}
}


### 1081 检查密码(15)

5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6

tips：说一行的最好就按照一行输入，因为符号包括空格

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
getchar();
while(n--) {
string str;
getline(cin, str);
int f1 = 0, f2 = 0, f3 = 0;
for(int i = 0; i < str.length(); i++) {
if(isdigit(str[i])) f1 = 1;
else if(islower(str[i]) || isupper(str[i])) f2 = 1;
else {
if(str[i] != '.') f3 = 1;
}
}
if(str.length() < 6) cout << "Your password is tai duan le.\n";
else if(f3 == 1) cout << "Your password is tai luan le.\n";
else if(f2 == 0) cout << "Your password needs zi mu.\n";
else if(f1 == 0) cout << "Your password needs shu zi.\n";
else cout << "Your password is wan mei.\n";
}
}


### 1082 射击比赛(20)

ID x y

3
0001 5 7
1020 -1 3
0233 0 -1

0233 0001

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e4 + 100;
struct peo {
string id;
double d;
} a[MAX];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string id;
double x, y;
cin >> id >> x >> y;
a[i].id = id;
a[i].d = x * x + y * y;
}
sort(a, a + n, [](peo a, peo b) {
return a.d < b.d;
});
cout << a[0].id << " " << a[n - 1].id << endl;
}


### 1083 是否存在相等的差(20)

8
3 5 8 6 2 1 4 7

5 2
3 3
2 2

#include <bits/stdc++.h>

using namespace std;
map<int, int> a;

int main() {
int n;
cin >> n;
int maxx = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[abs(x - i)]++;
maxx = max(maxx, abs(x - i));
}
for (int i = maxx; i >= 0; i--) {
if (a[i] > 1) {
cout << i << " " << a[i] << endl;
}
}
}


### 1084 外观数列(20)

d, d1, d111, d113, d11231, d112213111, …

1 8

1123123111

#include <bits/stdc++.h>

using namespace std;
map<int, int> a;

int main() {
int d, n;
cin >> d >> n;
n--;
string ans = to_string(d);
while (n--) {
string s = "";
for (int i = 0; i < ans.size(); i++) {
int tmp = 0;
s += ans[i];
if (ans[i] == ans[i + 1] && i + 1 < ans.size()) {
while (ans[i] == ans[i + 1] && i + 1 < ans.size()) {
i++, tmp++;
}
}
s += to_string(tmp + 1);
}
ans = s;
}
cout << ans;
}


### 1085 PAT单位排行(25)

10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu

5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

debug了很久，原因是我cnt=1开始++，

sort(a + 1, a + cnt），而不是sort(a + 1, a + cnt + 1);

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e5 + 10;
struct school {
string name;
double tot;
int cnt;
} a[MAX];
unordered_map<string, int> mp;

int main() {
int n;
cin >> n;
int cnt = 1;
while (n--) {
string str, name;
double num;
cin >> str >> num >> name;
for (int i = 0; i < name.size(); i++) {
name[i] = tolower(name[i]);
}
int pos = 0;
if (mp[name] == 0) {
mp[name] = cnt;
pos = cnt;
cnt++;
a[pos].tot = 0;
a[pos].cnt = 0;
} else pos = mp[name];
a[pos].cnt++;
a[pos].name = name;
if (str[0] == 'B') a[pos].tot += num / 1.5;
else if (str[0] == 'A') a[pos].tot += num;
else a[pos].tot += num * 1.5;
}
sort(a + 1, a + cnt, [](school a, school b) {
if ((int) a.tot != (int) b.tot) return (int) a.tot > (int) b.tot;
if (a.cnt != b.cnt) return a.cnt < b.cnt;
return a.name < b.name;
});
int pos = 1;
cout << cnt - 1 << endl;
for (int i = 1; i < cnt; i++) {
cout << pos << " " << a[i].name << " " << (int) a[i].tot << " " << a[i].cnt << endl;
if ((int) a[i].tot != (int) a[i + 1].tot) pos = i + 1;
}
}


### 1086 就不告诉你(15)

5 7

53

#include <bits/stdc++.h>

using namespace std;

int main() {
int a, b;
cin >> a >> b;
string ans = to_string(a * b);
int pos = ans.size() - 1;
while(ans[pos] == '0' && pos >= 0) pos--;
for(int i = pos; i >= 0; i--) {
cout << ans[i];
}
}


### 1087 有多少不同的值(20)

2017

1480

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
set<int> ans;
for (int i = 1; i <= n; i++) {
int tmp = i / 2 + i / 3 + i / 5;
ans.insert(tmp);
}
cout << ans.size() << endl;
}


### 1088 三人行(20)

48 3 7

48 Ping Cong Gai

48 11 6

No Solution

#include <bits/stdc++.h>

using namespace std;
double ans[5];

bool fuhe(int a, int x, int y) {
int b = (a / 10) + (a % 10) * 10;
double c = abs(a - b) * 1.0 / x;
if (b == c * y) {
ans[1] = a, ans[2] = b, ans[3] = c;
return 1;
}
return 0;
}

int main() {
int m, x, y;
cin >> m >> x >> y;
int maxx = 0;
for (int a1 = 10; a1 <= 99; a1++) {
if (fuhe(a1, x, y)) {
maxx = max(maxx, a1);
}
}
if (maxx == 0) cout << "No Solution" << endl;
else {
cout << maxx;
for (int i = 1; i <= 3; i++) {
if (m > ans[i]) cout << " Gai";
else if (m < ans[i]) cout << " Cong";
else cout << " Ping";
}
}
}


### 1089 狼人杀-简单版(20)

5
-2
+3
-4
+5
+4

1 4

6
+6
+3
+1
-5
-2
+4

1 5

5
-2
-3
-4
-5
-1

No Solution

#include <bits/stdc++.h>

using namespace std;
int a[110];

int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int f[110];
fill(f, f + 110, 1);
f[i] = f[j] = -1;
int cnt = 0;
vector<int> lie;
for (int k = 1; k <= n; k++) {
if (a[k] * f[abs(a[k])] < 0) {
cnt++;
lie.push_back(k);
}
}
if (cnt == 2 && f[lie[0]] + f[lie[1]] == 0) {
cout << i << " " << j << endl;
return 0;
}
}
}
cout << "No Solution" << endl;
}


### 1090 危险品装箱(25)

K G[1] G[2] … G[K]

6 3
20001 20002
20003 20004
20005 20006
20003 20001
20005 20004
20004 20006
4 00001 20004 00002 20003
5 98823 20002 20003 20006 10010
3 12345 67890 23333

No
Yes
Yes

#include <bits/stdc++.h>

using namespace std;
map<string, set<string> > mp;

int main() {
int n, m;
cin >> n >> m;
getchar();
for (int i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
mp[b].insert(a);
mp[a].insert(b);
}
while (m--) {
int n;
cin >> n;
bool flag = 1;
set<string> have;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
have.insert(s);
}
for (auto x: have) {
for (auto y: mp[x]) {
if (have.find(y) != have.end()) flag = 0;
}
}
if (flag == 1) printf("Yes\n");
else printf("No\n");
}
}


### 1091 N-自守数(15)

1091 N-自守数 (15 分)

3
92 5 233

3 25392
1 25
No

#include <bits/stdc++.h>

using namespace std;

bool solve(int k, int n) {
int tmp = n * k * k;
while (k != 0) {
if (k % 10 == tmp % 10) {
k /= 10;
tmp /= 10;
} else return 0;
}
return 1;
}

int main() {
int n;
cin >> n;
while (n--) {
int k;
cin >> k;
bool flag = 0;
for (int i = 0; i < 10; i++) {
if (solve(k, i)) {
cout << i << " " << i * k * k << endl;
flag = 1;
break;
}
}
if (flag == 0) cout << "No\n";

}
}


### 1092 最好吃的月饼(20)

5 3
1001 992 0 233 6
8 0 2018 0 2008
36 18 0 1024 4

2018
3 5

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
ll sum[1100];

int main() {
int n, m;
cin >> n >> m;
ll maxsum = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
ll x;
cin >> x;
sum[j] += x;
}
}
for (int i = 0; i < n; i++) {
maxsum = max(maxsum, sum[i]);
}
cout << maxsum << endl;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (maxsum == sum[i]) {
if (cnt != 0) cout << " ";
cout << i + 1;
cnt++;
}
}
}


### 1093 字符串A+B(20)

This is a sample test
to show you_How it works

This ampletowyu_Hrk

#include <bits/stdc++.h>

using namespace std;

int main() {
string s1, s2;
getline(cin, s1);
getline(cin, s2);
set<char> have;
for (int i = 0; i < s1.length(); i++) {
if (have.find(s1[i]) != have.end()) {
continue;
}
cout << s1[i];
have.insert(s1[i]);
}
for (int i = 0; i < s2.length(); i++) {
if (have.find(s2[i]) != have.end()) {
continue;
}
cout << s2[i];
have.insert(s2[i]);
}
}


### 1094 谷歌的招聘(20)

2004 年 7 月，谷歌在硅谷的 101 号公路边竖立了一块巨大的广告牌（如下图）用于招聘。内容超级简单，就是一个以 .com 结尾的网址，而前面的网址是一个 10 位素数，这个素数是自然常数 e 中最早出现的 10 位连续数字。能找出这个素数的人，就可以通过访问谷歌的这个网站进入招聘流程的下一步。

20 5
23654987725541023819

49877

10 3
2468001680

404

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

bool isp(ll x) {
if (x <= 1) return 0;
for (ll i = 2; i <= x / i; i++) {
if (x % i == 0) return 0;
}
return 1;
}

int main() {
int l, k;
cin >> l >> k;
string str;
cin >> str;
for (int i = 0; i + k - 1 < str.length(); i++) {
ll res = 0;
for (int j = i; j < i + k; j++) {
res = res * 10 + str[j] - '0';
}
if (isp(res)) {
string ans = "";
ans += string(k - to_string(res).length(), '0');
ans += to_string(res);
cout << ans << endl;
return 0;
}
}
cout << "404" << endl;
}


### 1095 解码PAT准考证(25)

PAT 准考证号由 4 部分组成：

8 4
B123180908127 99
B102180908003 86
A112180318002 98
T107150310127 62
A107180908108 100
T123180908010 78
B112160918035 88
A107180908021 98
1 A
2 107
3 180908
2 999

Case 1: 1 A
A107180908108 100
A107180908021 98
A112180318002 98
Case 2: 2 107
3 260
Case 3: 3 180908
107 2
123 2
102 1
Case 4: 2 999
NA

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e4 + 10;
unordered_map<int, unordered_map<int, int> > day;
int cnt[MAX];
int tot[MAX];
struct stu {
string xue;
int num;
} a[4][MAX];
int pos[4];

int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
string str;
int num;
cin >> str >> num;
if (str[0] == 'B') {
a[0][pos[0]].xue = str, a[0][pos[0]++].num = num;
} else if (str[0] == 'A') {
a[1][pos[1]].xue = str, a[1][pos[1]++].num = num;
} else {
a[2][pos[2]].xue = str, a[2][pos[2]++].num = num;
}
int s = stoi(str.substr(1, 3)), t = stoi(str.substr(4, 6));
cnt[s]++;
tot[s] += num;
day[t][s]++;
}
for (int i = 0; i < 3; i++) {
sort(a[i], a[i] + pos[i], [](stu a, stu b) {
if (a.num != b.num) return a.num > b.num;
return a.xue < b.xue;
});
}
int casee = 0;
while (q--) {
casee++;
int x;
string str;
cin >> x >> str;
cout << "Case " << casee << ": " << x << " " << str << endl;
if (x == 1) {
if (str == "B" && pos[0] == 0 || str == "A" && pos[1] == 0 || str == "T" && pos[2] == 0) {
printf("NA\n");
continue;
}
int pospos = 0;
if (str == "B") pospos = 0;
else if (str == "A") pospos = 1;
else pospos = 2;
for (int i = 0; i < pos[pospos]; i++) {
cout << a[pospos][i].xue << " " << a[pospos][i].num << endl;
}
} else if (x == 2) {
int y = stoi(str);
if (cnt[y] == 0) {
printf("NA\n");
continue;
}
printf("%d %d\n", cnt[y], tot[y]);
} else {
if (day[stoi(str)].size() == 0) {
printf("NA\n");
continue;
}
vector<pair<int, int> > ans;
for (auto x: day[stoi(str)]) {
ans.push_back({x.first, x.second});
}
sort(ans.begin(), ans.end(), [](pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) return a.second > b.second;
return a.first < b.first;
});
for (auto x: ans) {
cout << x.first << " " << x.second << endl;
}
}
}
}


### 1096 大美数(15)

3
18 29 40

Yes
No
Yes

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e4 + 10;
int a[MAX];

bool solve(int x) {
int pos = 0;
for (int i = 1; i <= x / i; i++) {
if (x % i == 0) {
a[pos++] = i;
if (i * i != x) a[pos++] = x / i;
}
}
int sum = 0;
for (int i = 0; i < pos; i++) {
for (int j = i + 1; j < pos; j++) {
for (int k = j + 1; k < pos; k++) {
for (int l = k + 1; l < pos; l++) {
sum = a[i] + a[j] + a[k] + a[l];
if (sum % x == 0) return 1;
}
}
}
}
return 0;
}

int main() {
int k;
cin >> k;
while (k--) {
int x;
cin >> x;
if (solve(x)) printf("Yes\n");
else printf("No\n");
}
}


### 1097 阵行平移(20)

7 2 99
11 87 23 67 20 75 89
37 94 27 91 63 50 11
44 38 50 26 40 26 24
73 85 63 28 62 18 68
15 83 27 97 88 25 43
23 78 98 20 30 81 99
77 36 48 59 25 34 22

529 481 479 263 417 342 343

99 11 87 23 67 20 75
37 94 27 91 63 50 11
99 99 44 38 50 26 40
73 85 63 28 62 18 68
99 15 83 27 97 88 25
23 78 98 20 30 81 99
99 99 77 36 48 59 25

#include <bits/stdc++.h>

using namespace std;
int g[110][110];

int main() {
int n, k, x;
cin >> n >> k >> x;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> g[i][j];
}
}
int pos = 1;
for (int i = 1; i <= n; i += 2) {
for (int j = n; j - pos >= 1; j--) {
g[i][j] = g[i][j - pos];
}
for (int j = 1; j <= pos; j++) {
g[i][j] = x;
}
pos++;
if (pos == k + 1) pos = 1;
}
for (int j = 1; j <= n; j++) {
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += g[i][j];
}
if (j != 1) cout << " ";
cout << sum;
}
}


### 1098 岩洞施工(20)

11
7 6 5 5 6 5 4 5 5 4 4
3 2 2 2 2 3 3 2 1 2 3

Yes 1

11
7 6 5 5 6 5 4 5 5 4 4
3 2 2 2 3 4 3 2 1 2 3

No 1

#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
int min1 = 1100, max2 = -1;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
min1 = min(min1, x);
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
max2 = max(max2, x);
}
if (min1 - 1 >= max2) {
cout << "Yes " << min1 - max2;
} else {
int ans = 0;
if (min1 <= max2) ans = max2 - min1 + 1;
else ans = min1 - max2 + 1;
cout << "No " << ans;
}
}


### 1099 性感素数(20)

“性感素数”是指形如 (p, p+6) 这样的一对素数。之所以叫这个名字，是因为拉丁语管“六”叫“sex”（即英语的“性感”）。（原文摘自 http://mathworld.wolfram.com/SexyPrimes.html）

47

Yes
41

21

No
23

#include <bits/stdc++.h>

using namespace std;
int ans;

bool isp(int x) {
if (x <= 1) return 0;
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) return 0;
}
return 1;
}

bool solve(int x) {
if (isp(x)) {
if (isp(x - 6)) {
ans = x - 6;
return 1;
}
if (isp(x + 6)) {
ans = x + 6;
return 1;
}
}
for (int i = x + 1; i; i++) {
if (isp(i)) {
if (isp(i - 6)) {
ans = i;
return 0;
}
if (isp(i + 6)) {
ans = i;
return 0;
}

}
}
}

int main() {
int x;
cin >> x;
if (solve(x)) cout << "Yes\n";
else cout << "No\n";
cout << ans << endl;
}


### 1100 校庆(25)

2019 年浙江大学将要庆祝成立 122 周年。为了准备校庆，校友会收集了所有校友的身份证号。现在需要请你编写程序，根据来参加校庆的所有人士的身份证号，统计来了多少校友。

5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042

3
150702193604190912

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e4 + 10;
set<string> have;

int main() {
int n, m;
cin >> n;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
have.insert(str);
}
string maxx = "99999999";
string ans;
int cnt = 0;
cin >> m;
for (int i = 0; i < m; i++) {
string str;
cin >> str;
if (have.find(str) != have.end()) cnt++;
if (str.substr(6, 8) < maxx) {
maxx = str.substr(6, 8);
ans = str;
}
}
cout << cnt << endl;
cout << ans << endl;
}


### 1101 B是A的多少倍(15)

12345 2

3.66

12345 5

1.00

#include <bits/stdc++.h>
using namespace std;
int main() {
int s, x;
cin >> s >> x;
int len = to_string(s).length() - x;
x = pow(10, x);
double t = (s / x) + (s % x) * pow(10, len);
printf("%.2f", t / s);
}


### 1102 教超冠军卷(20)

“教育超市”是拼题 A 系统的一个衍生产品，发布了各种试卷和练习供用户选购。在试卷列表中，系统不仅列出了每份试卷的单价，还显示了当前的购买人次。本题就请你根据这些信息找出教育超市所有试卷中的销量（即购买人次）冠军和销售额冠军。

4
zju007 39 10
pku2019 9 332
pat2018 95 79
qdu106 19 38

pku2019 332
pat2018 7505

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
struct node {
string str;
int num, v;
int sum;
} a[11010];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].str >> a[i].v >> a[i].num;
a[i].sum = a[i].num * a[i].v;
}
sort(a, a + n, [](node a, node b) {
return a.num > b.num;
});
cout << a[0].str << " " << a[0].num << endl;
sort(a, a + n, [](node a, node b) {
return a.sum > b.sum;
});
cout << a[0].str << " " << a[0].sum << endl;
}


### 1103 缘分数(20)

8 200

8 3
105 10

9 100

No Solution

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
typedef long long ll;
map<ll, ll> a;

void init() {
for (ll i = 1; i <= MAX; i++) {
ll tmp = i * i + (i - 1) * (i - 1);
a.insert({tmp, i});
}
}

int main() {
init();
ll n, m;
cin >> n >> m;
int cnt = 0;
for (ll i = max(2ll, n); i <= m; i++) {
ll tmp = 3 * i * i - 3 * i + 1;
ll sq = sqrt(tmp);
if (sq * sq == tmp && a[sq] != 0) {
cout << i << " " << a[sq] << endl;
cnt++;
}
}
if (cnt == 0) cout << "No Solution";
}


### 1104 天长地久(20)

“天长地久数”是指一个 K 位正整数 A，其满足条件为：A 的各位数字之和为 m，A+1 的各位数字之和为 n，且 m 与 n 的最大公约数是一个大于 2 的素数。本题就请你找出这些天长地久数。

2
6 45
7 80

Case 1
10 189999
10 279999
10 369999
10 459999
10 549999
10 639999
10 729999
10 819999
10 909999
Case 2
No Solution

#include <bits/stdc++.h>

using namespace std;

bool isp(int x) {
if (x <= 1) return 0;
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) return 0;
}
return 1;
}

vector<string> ans;

void solve(int n, int m, int k) {
int num = (n - m + 1) / 9;
int shen = n - num * 9;
int minn = pow(10, k - num - 1);
int maxx = pow(10, k - num);
for (int i = minn; i < maxx; i++) {
string s = to_string(i);
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += s[i] - '0';
}
if (sum == shen && i % 10 != 9)
ans.push_back(to_string(m) + " " + s + string(num, '9'));
}
}

int main() {
int q;
cin >> q;
for (int i = 0; i < q; i++) {
cout << "Case " << i + 1 << endl;
int k, n;
cin >> k >> n;
int l = 1, r = k * 9;
for (int i = l; i + 1 <= r; i++) {
int gcd = __gcd(n, i);
if (gcd > 2 && isp(gcd)) {
int cha = (n - i) + 1;
if (cha % 9 == 0 && cha > 0) {
solve(n, i, k);
}
}
}
if (ans.size() == 0) {
cout << "No Solution" << endl;
continue;
}
sort(ans.begin(), ans.end());
for (auto x: ans) {
cout << x << endl;
}
ans.clear();
}
}


### 1105 链表合并(25)

⋯ 的结果。例如给定两个链表分别为 6→7 和 1→2→3→4→5，你应该输出 1→2→7→3→4→6→5。

00100 01000 7
02233 2 34891
00100 6 00001
34891 3 10086
01000 1 02233
00033 5 -1
10086 4 00033
00001 7 -1

01000 1 02233
02233 2 00001
00001 7 34891
34891 3 10086
10086 4 00100
00100 6 00033
00033 5 -1

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
struct node {
int add, data, next;
} c[MAX];

int main() {
int a1, a2, n;
cin >> a1 >> a2 >> n;
for (int i = 0; i < n; i++) {
}
int pos0 = 0, pos1 = 0;
int aa1 = a1;
vector<node> havea, haveb;
while (aa1 != -1) {
pos0++;
havea.push_back(c[aa1]);
aa1 = c[aa1].next;
}
int aa2 = a2;
while (aa2 != -1) {
pos1++;
haveb.push_back(c[aa2]);
aa2 = c[aa2].next;
}
int start;
vector<node> ans;
if (pos0 >= 2 * pos1) {
start = a1;
for (int i = 0, j = haveb.size() - 1; i < havea.size();) {
if (i < havea.size()) ans.push_back(havea[i++]);
if (i < havea.size()) ans.push_back(havea[i++]);
if (j >= 0) ans.push_back(haveb[j--]);
}
} else {
start = a2;
for (int i = 0, j = havea.size() - 1; i < haveb.size();) {
if (i < haveb.size()) ans.push_back(haveb[i++]);
if (i < haveb.size()) ans.push_back(haveb[i++]);
if (j >= 0) ans.push_back(havea[j--]);
}
}
for (int i = 0; i < ans.size(); i++) {
if (i != ans.size() - 1) printf("%05d %d %05d\n", start, ans[i].data, ans[i + 1].add);
else printf("%05d %d -1\n", start, ans[i].data);
start = ans[i + 1].add;
}
}


### 1106 2019数列(15)

10

2019224758

#include <bits/stdc++.h>

using namespace std;
int a[1100];

int main() {
int n;
cin >> n;
a[1] = 2, a[2] = 0, a[3] = 1, a[4] = 9;
for (int i = 5; i <= n; i++) {
int x = 0;
for (int j = i - 1; j >= i - 4; j--) {
x += a[j];
}
a[i] = x % 10;
}
for (int i = 1; i <= n; i++) {
cout << a[i];
}
}


### 1107 老鼠爱大米(20)

3 5
62 53 88 72 81
12 31 9 0 2
91 42 39 6 48

88 31 91
91

#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ans = -1;
for (int i = 0; i < n; i++) {
int maxx = -1;
for (int j = 0; j < m; j++) {
int x;
cin >> x;
maxx = max(maxx, x);
}
if (i != 0) cout << " ";
cout << maxx;
ans = max(ans, maxx);
}
cout << endl;
cout << ans << endl;
}


### 1108 String复读机(20)

sTRidlinSayBingStrropriiSHSiRiagIgtSSr

StringStringSrigSriSiSii

#include <bits/stdc++.h>

using namespace std;
string s = "String";
int ch[320];

int main() {
string str;
getline(cin, str);
for (int i = 0; i < str.length(); i++) {
ch[str[i] - '0']++;
}
while (1) {
bool f = 1;
for (int i = 0; i < s.length(); i++) {
if (ch[s[i] - '0'] != 0) {
f = 0;
cout << s[i];
ch[s[i] - '0']--;
}
}
if (f == 1) break;
}
}


### 1109 擅长C(20)

…C…
.C.C.
C…C
CCCCC
C…C
C…C
C…C
CCCC.
C…C
C…C
CCCC.
C…C
C…C
CCCC.
.CCC.
C…C
C…
C…
C…
C…C
.CCC.
CCCC.
C…C
C…C
C…C
C…C
C…C
CCCC.
CCCCC
C…
C…
CCCC.
C…
C…
CCCCC
CCCCC
C…
C…
CCCC.
C…
C…
C…
CCCC.
C…C
C…
C.CCC
C…C
C…C
CCCC.
C…C
C…C
C…C
CCCCC
C…C
C…C
C…C
CCCCC
…C…
…C…
…C…
…C…
…C…
CCCCC
CCCCC
…C
…C
…C
…C
C…C
.CCC.
C…C
C…C.
C.C…
CC…
C.C…
C…C.
C…C
C…
C…
C…
C…
C…
C…
CCCCC
C…C
C…C
CC.CC
C.C.C
C…C
C…C
C…C
C…C
C…C
CC…C
C.C.C
C…CC
C…C
C…C
.CCC.
C…C
C…C
C…C
C…C
C…C
.CCC.
CCCC.
C…C
C…C
CCCC.
C…
C…
C…
.CCC.
C…C
C…C
C…C
C.C.C
C…CC
.CCC.
CCCC.
C…C
CCCC.
CC…
C.C…
C…C.
C…C
.CCC.
C…C
C…
.CCC.
…C
C…C
.CCC.
CCCCC
…C…
…C…
…C…
…C…
…C…
…C…
C…C
C…C
C…C
C…C
C…C
C…C
.CCC.
C…C
C…C
C…C
C…C
C…C
.C.C.
…C…
C…C
C…C
C…C
C.C.C
CC.CC
C…C
C…C
C…C
C…C
.C.C.
…C…
.C.C.
C…C
C…C
C…C
C…C
.C.C.
…C…
…C…
…C…
…C…
CCCCC
…C
…C.
…C…
.C…
C…
CCCCC
HELLO~WORLD!

C…C CCCCC C… C… .CCC.
C…C C… C… C… C…C
C…C C… C… C… C…C
CCCCC CCCC. C… C… C…C
C…C C… C… C… C…C
C…C C… C… C… C…C
C…C CCCCC CCCCC CCCCC .CCC.

C…C .CCC. CCCC. C… CCCC.
C…C C…C C…C C… C…C
C…C C…C CCCC. C… C…C
C.C.C C…C CC… C… C…C
CC.CC C…C C.C… C… C…C
C…C C…C C…C. C… C…C
C…C .CCC. C…C CCCCC CCCC.

#include <bits/stdc++.h>

using namespace std;
char g[30][10][7];

void init() {
for (int i = 1; i <= 26; i++) {
for (int j = 1; j <= 7; j++) {
for (int k = 1; k <= 5; k++) {
cin >> g[i][j][k];
}
}
}
}

int main() {
init();
string str;
getchar();
getline(cin, str);
int pos = 0;
vector<string> ans;
while (pos < str.length()) {
if (isupper(str[pos])) {
string res = "";
while (pos < str.length() && isupper(str[pos])) {
res += str[pos];
pos++;
}
ans.push_back(res);
}
pos++;
}
for (int ii = 0; ii < ans.size(); ii++) {
if (ii != 0) cout << endl;
for (int i = 1; i <= 7; i++) {
for (int j = 0; j < ans[ii].size(); j++) {
if (j != 0) cout << " ";
for (int k = 1; k <= 5; k++) {
cout << g[ans[ii][j] - 'A' + 1][i][k];
}
}
cout << endl;
}
}
}


### 1110 区块反转(25)

00100 8 3
71120 7 88666
00000 4 99999
00100 1 12309
68237 6 71120
33218 3 00000
99999 5 68237
88666 8 -1
12309 2 33218

71120 7 88666
88666 8 00000
00000 4 99999
99999 5 68237
68237 6 00100
00100 1 12309
12309 2 33218
33218 3 -1

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
struct node {
int add, data, next;
} c[MAX];

int main() {
int a, n, k;
cin >> a >> n >> k;
for (int i = 0; i < n; i++) {
}
int cnt = 0;
vector<node> ans;
vector<node> zhan;
while (a != -1) {
cnt++;
zhan.push_back(c[a]);
if (cnt == k) {
cnt = 0;
reverse(zhan.begin(), zhan.end());
for (auto x: zhan) {
ans.push_back(x);
}
zhan.clear();
}
a = c[a].next;
}
reverse(zhan.begin(), zhan.end());
for (auto x: zhan) {
ans.push_back(x);
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
if (i != ans.size() - 1) printf("%05d %d %05d\n", ans[i].add, ans[i].data, ans[i + 1].add);
else printf("%05d %d -1\n", ans[i].add, ans[i].data);
}
}
，目标是抢吃尽可能多的大米让自己变成胖胖鼠，最胖的那只就是冠军。

3 5
62 53 88 72 81
12 31 9 0 2
91 42 39 6 48

88 31 91
91

cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ans = -1;
for (int i = 0; i < n; i++) {
int maxx = -1;
for (int j = 0; j < m; j++) {
int x;
cin >> x;
maxx = max(maxx, x);
}
if (i != 0) cout << " ";
cout << maxx;
ans = max(ans, maxx);
}
cout << endl;
cout << ans << endl;
}


### 1108 String复读机(20)

sTRidlinSayBingStrropriiSHSiRiagIgtSSr

StringStringSrigSriSiSii

#include <bits/stdc++.h>

using namespace std;
string s = "String";
int ch[320];

int main() {
string str;
getline(cin, str);
for (int i = 0; i < str.length(); i++) {
ch[str[i] - '0']++;
}
while (1) {
bool f = 1;
for (int i = 0; i < s.length(); i++) {
if (ch[s[i] - '0'] != 0) {
f = 0;
cout << s[i];
ch[s[i] - '0']--;
}
}
if (f == 1) break;
}
}


### 1109 擅长C(20)

…C…
.C.C.
C…C
CCCCC
C…C
C…C
C…C
CCCC.
C…C
C…C
CCCC.
C…C
C…C
CCCC.
.CCC.
C…C
C…
C…
C…
C…C
.CCC.
CCCC.
C…C
C…C
C…C
C…C
C…C
CCCC.
CCCCC
C…
C…
CCCC.
C…
C…
CCCCC
CCCCC
C…
C…
CCCC.
C…
C…
C…
CCCC.
C…C
C…
C.CCC
C…C
C…C
CCCC.
C…C
C…C
C…C
CCCCC
C…C
C…C
C…C
CCCCC
…C…
…C…
…C…
…C…
…C…
CCCCC
CCCCC
…C
…C
…C
…C
C…C
.CCC.
C…C
C…C.
C.C…
CC…
C.C…
C…C.
C…C
C…
C…
C…
C…
C…
C…
CCCCC
C…C
C…C
CC.CC
C.C.C
C…C
C…C
C…C
C…C
C…C
CC…C
C.C.C
C…CC
C…C
C…C
.CCC.
C…C
C…C
C…C
C…C
C…C
.CCC.
CCCC.
C…C
C…C
CCCC.
C…
C…
C…
.CCC.
C…C
C…C
C…C
C.C.C
C…CC
.CCC.
CCCC.
C…C
CCCC.
CC…
C.C…
C…C.
C…C
.CCC.
C…C
C…
.CCC.
…C
C…C
.CCC.
CCCCC
…C…
…C…
…C…
…C…
…C…
…C…
C…C
C…C
C…C
C…C
C…C
C…C
.CCC.
C…C
C…C
C…C
C…C
C…C
.C.C.
…C…
C…C
C…C
C…C
C.C.C
CC.CC
C…C
C…C
C…C
C…C
.C.C.
…C…
.C.C.
C…C
C…C
C…C
C…C
.C.C.
…C…
…C…
…C…
…C…
CCCCC
…C
…C.
…C…
.C…
C…
CCCCC
HELLO~WORLD!

C…C CCCCC C… C… .CCC.
C…C C… C… C… C…C
C…C C… C… C… C…C
CCCCC CCCC. C… C… C…C
C…C C… C… C… C…C
C…C C… C… C… C…C
C…C CCCCC CCCCC CCCCC .CCC.

C…C .CCC. CCCC. C… CCCC.
C…C C…C C…C C… C…C
C…C C…C CCCC. C… C…C
C.C.C C…C CC… C… C…C
CC.CC C…C C.C… C… C…C
C…C C…C C…C. C… C…C
C…C .CCC. C…C CCCCC CCCC.

#include <bits/stdc++.h>

using namespace std;
char g[30][10][7];

void init() {
for (int i = 1; i <= 26; i++) {
for (int j = 1; j <= 7; j++) {
for (int k = 1; k <= 5; k++) {
cin >> g[i][j][k];
}
}
}
}

int main() {
init();
string str;
getchar();
getline(cin, str);
int pos = 0;
vector<string> ans;
while (pos < str.length()) {
if (isupper(str[pos])) {
string res = "";
while (pos < str.length() && isupper(str[pos])) {
res += str[pos];
pos++;
}
ans.push_back(res);
}
pos++;
}
for (int ii = 0; ii < ans.size(); ii++) {
if (ii != 0) cout << endl;
for (int i = 1; i <= 7; i++) {
for (int j = 0; j < ans[ii].size(); j++) {
if (j != 0) cout << " ";
for (int k = 1; k <= 5; k++) {
cout << g[ans[ii][j] - 'A' + 1][i][k];
}
}
cout << endl;
}
}
}


### 1110 区块反转(25)

00100 8 3
71120 7 88666
00000 4 99999
00100 1 12309
68237 6 71120
33218 3 00000
99999 5 68237
88666 8 -1
12309 2 33218

71120 7 88666
88666 8 00000
00000 4 99999
99999 5 68237
68237 6 00100
00100 1 12309
12309 2 33218
33218 3 -1

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 10;
struct node {
int add, data, next;
} c[MAX];

int main() {
int a, n, k;
cin >> a >> n >> k;
for (int i = 0; i < n; i++) {
}
int cnt = 0;
vector<node> ans;
vector<node> zhan;
while (a != -1) {
cnt++;
zhan.push_back(c[a]);
if (cnt == k) {
cnt = 0;
reverse(zhan.begin(), zhan.end());
for (auto x: zhan) {
ans.push_back(x);
}
zhan.clear();
}
a = c[a].next;
}
reverse(zhan.begin(), zhan.end());
for (auto x: zhan) {
ans.push_back(x);
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
if (i != ans.size() - 1) printf("%05d %d %05d\n", ans[i].add, ans[i].data, ans[i + 1].add);
else printf("%05d %d -1\n", ans[i].add, ans[i].data);
}
}

• 4
点赞
• 44
收藏
觉得还不错? 一键收藏
• 4
评论
02-20
02-24 4315
11-13 2004
10-19 8万+
04-27
09-09
03-31