Posted on 2008-03-29 22:11
superman 阅读(234)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1042 C++ 00:00.00 852K */
2 #include <string>
3 #include <iostream>
4
5 using namespace std;
6
7 int main()
8 {
9 int k1, k2, k3;
10 while(cin >> k1 >> k2 >> k3)
11 {
12 if(k1 == 0 && k2 == 0 && k3 == 0)
13 break;
14
15 string message;
16 cin >> message;
17
18 string g1, g2, g3;
19 int pos1[100], c1 = 0, pos2[100], c2 = 0, pos3[100], c3 = 0;
20 for(int i = 0; i < message.size(); i++)
21 {
22 if('a' <= message[i] && message[i] <= 'i')
23 {
24 g1 += message[i];
25 pos1[c1++] = i;
26 continue;
27 }
28 if('j' <= message[i] && message[i] <= 'r')
29 {
30 g2 += message[i];
31 pos2[c2++] = i;
32 continue;
33 }
34 g3 += message[i];
35 pos3[c3++] = i;
36 }
37
38 k1 = (c1 == 0 ? 0 : k1 % c1);
39 k2 = (c2 == 0 ? 0 : k2 % c2);
40 k3 = (c3 == 0 ? 0 : k3 % c3);
41
42 string t1, t2, t3;
43
44 for(int i = g1.size() - k1; i < g1.size(); i++)
45 t1 += g1[i];
46 for(int i = 0; i < g1.size() - k1; i++)
47 t1 += g1[i];
48
49 for(int i = g2.size() - k2; i < g2.size(); i++)
50 t2 += g2[i];
51 for(int i = 0; i < g2.size() - k2; i++)
52 t2 += g2[i];
53
54 for(int i = g3.size() - k3; i < g3.size(); i++)
55 t3 += g3[i];
56 for(int i = 0; i < g3.size() - k3; i++)
57 t3 += g3[i];
58
59 for(int i = 0; i < c1; i++)
60 message[pos1[i]] = t1[i];
61 for(int i = 0; i < c2; i++)
62 message[pos2[i]] = t2[i];
63 for(int i = 0; i < c3; i++)
64 message[pos3[i]] = t3[i];
65
66 cout << message << endl;
67 }
68
69 return 0;
70 }
71