Posted on 2008-05-14 18:14
superman 阅读(184)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1279 C++ 00:00.00 840K */
2 #include <iostream>
3
4 using namespace std;
5
6 int main()
7 {
8 int N;
9 cin >> N;
10
11 cout << "COWCULATIONS OUTPUT" << endl;
12
13 while(N--)
14 {
15 char a[8], b[8], d[8], op;
16 char alen = 0, blen = 0, dlen = 0;
17
18 memset(a, 0, sizeof(a));
19 memset(b, 0, sizeof(b));
20 memset(d, 0, sizeof(d));
21
22 string s;
23
24 cin >> s;
25 {
26 int i = 0;
27 while(s[i] == 'V')
28 i++;
29 int p = 0;
30 while(i < 5)
31 a[p++] = s[i++];
32 alen = p;
33 }
34 for(int i = 0; i < alen / 2; i++)
35 swap(a[i], a[alen - i - 1]);
36 for(int i = 0; i < alen; i++)
37 switch(a[i])
38 {
39 case 'V' : a[i] = 0; break;
40 case 'U' : a[i] = 1; break;
41 case 'C' : a[i] = 2; break;
42 case 'D' : a[i] = 3; break;
43 }
44
45 cin >> s;
46 {
47 int i = 0;
48 while(s[i] == 'V')
49 i++;
50 int p = 0;
51 while(i < 5)
52 b[p++] = s[i++];
53 blen = p;
54 }
55 for(int i = 0; i < blen / 2; i++)
56 swap(b[i], b[blen - i - 1]);
57 for(int i = 0; i < blen; i++)
58 switch(b[i])
59 {
60 case 'V' : b[i] = 0; break;
61 case 'U' : b[i] = 1; break;
62 case 'C' : b[i] = 2; break;
63 case 'D' : b[i] = 3; break;
64 }
65
66 //compute
67 for(int k = 0; k < 3; k++)
68 {
69 cin >> op;
70 if(op == 'A')
71 {
72 char c[6], clen;
73 memset(c, 0, sizeof(c));
74
75 clen = max(alen, blen);
76 for(int i = 0; i < clen; i++)
77 c[i] = a[i] + b[i];
78 for(int i = 0; i < clen; i++)
79 c[i + 1] += c[i] / 4, c[i] %= 4;
80
81 if(c[clen])
82 clen++;
83
84 blen = clen;
85 memcpy(b, c, sizeof(c));
86 }
87 if(op == 'L')
88 {
89 for(int i = blen; i >= 1; i--)
90 b[i] = b[i - 1];
91 b[0] = 0;
92 blen++;
93 }
94 if(op == 'R')
95 {
96 for(int i = 0; i < blen - 1; i++)
97 b[i] = b[i + 1];
98 b[blen - 1] = 0;
99 blen--;
100 }
101 }
102
103 cin >> s;
104 {
105 int i = 0;
106 while(s[i] == 'V')
107 i++;
108 int p = 0;
109 while(i < 8)
110 d[p++] = s[i++];
111 dlen = p;
112 }
113 for(int i = 0; i < dlen / 2; i++)
114 swap(d[i], d[dlen - i - 1]);
115 for(int i = 0; i < dlen; i++)
116 switch(d[i])
117 {
118 case 'V' : d[i] = 0; break;
119 case 'U' : d[i] = 1; break;
120 case 'C' : d[i] = 2; break;
121 case 'D' : d[i] = 3; break;
122 }
123
124 if(blen == dlen)
125 {
126 int i;
127 for(i = 0; i < blen; i++)
128 if(b[i] != d[i])
129 {
130 cout << "NO" << endl; break;
131 }
132 if(i == blen)
133 cout << "YES" << endl;
134 }
135 else
136 cout << "NO" << endl;
137 }
138
139 cout << "END OF OUTPUT" << endl;
140
141 return 0;
142 }
143