Book

1006 换个格式输出整数

输入234,输出BBSSS1234。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;

int main() {
int n;
scanf("%d", &n);
int index = 0, ans[4];
while (n != 0) {
ans[index++] = n % 10;
n /= 10;
}
for (int i = index - 1; i >= 0; i--) {
if (i == 2) {
for (int j = 0; j < ans[i]; j++) {
printf("B");
}
} else if (i == 1) {
for (int j = 0; j < ans[i]; j++) {
printf("S");
}
} else if (i == 0) {
for (int j = 1; j <= ans[i]; j++) {
printf("%d", j);
}
}
}

return 0;
}

234
BBSSS1234

1021 个位数统计

统计一个不超过1000位的数字的各个数字出现次数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;

int main() {
char str[1100];
cin >> str;
int len = strlen(str);
int cnt[10] = {0};
for (int i = 0; i < len; i++) {
cnt[str[i] - '0']++;
}
for (int i = 0; i < 10; i++) {
if (cnt[i] != 0) {
printf("%d:%d\n", i, cnt[i]);
}
}

return 0;
}

100311
0:2
1:3
3:1

1031 查验身份证

1
2
3
4
5
6
7
8



4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X