简单字符串。
1 #include <stdio.h>
2
3 #define MAXLEN 160
4
5 char buf[MAXLEN];
6 int keys[4], parts[4];
7
8 void getpart(int x) {
9 int i;
10 for (i=3; i>=0; --i) {
11 parts[i] = x%100;
12 x /= 100;
13 }
14 }
15
16 int main() {
17 int case_n, n, max, mm;
18 int i, j, k, flag, tmp, len;
19
20 scanf("%d", &case_n);
21 while (case_n--) {
22 scanf("%d", &n);
23 max = 0;
24 for (i=0; i<4; ++i) {
25 scanf("%d",&keys[i]);
26 if (max < keys[i]) {
27 max = keys[i];
28 mm = i;
29 }
30 }
31 len = 0;
32 for (i=0; i<n; ++i) {
33 scanf("%d", &tmp);
34 getpart(tmp);
35 for (j=10000;;++j)
36 if (j%max == parts[mm])
37 break;
38 while (1) {
39 flag = 1;
40 for (k=0; k<4; ++k) {
41 if (k == mm) continue;
42 if (j%keys[k] != parts[k]) {
43 flag = 0;
44 break;
45 }
46 }
47 if (flag) break;
48 j += max;
49 }
50 getpart(j);
51 for (k=1; k<4; ++k) {
52 if (parts[k] == 27)
53 buf[len++] = ‘ ‘;
54 else
55 buf[len++] = (char)(parts[k])+‘A‘-1;
56 }
57 }
58 while (buf[--len] == ‘ ‘) ;
59 buf[len+1] = ‘\0‘;
60 printf("%s\n", buf);
61 }
62
63 return 0;
64 }
【HDOJ】1930 And Now, a Remainder from Our Sponsor,布布扣,bubuko.com
时间: 2024-11-05 13:06:06