/home/toolbox/public_html/solutions/3/377/a.c
1 #include <stdio.h>
2 #include <strings.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7
8 #define TRUE (1 == 1)
9 #define FALSE (1 != 1)
10
11 #define DEBUG if (FALSE)
12
13 /* fprintf(stderr, "functionName: message", varslist); */
14
15 /*
16 * Author: Isaac Traxler
17 * Date: 2005-03-05
18 * Purpose:
19 * Problem: 10377
20 */
21
22 /*
23 * This template reads data a specified number of times.
24 */
25
26 int numberOfTimes;
27 int num1, num2, num3;
28 char op[3];
29
30
31 int init()
32 {
33 /* FUNCTION init */
34 scanf("%d ", &numberOfTimes);
35 } /* FUNCTION init */
36
37 void dump()
38 {
39 /* FUNCTION dump */
40 } /* FUNCTION dump */
41
42 void getInput()
43 {
44 /* FUNCTION getInput */
45 int i;
46
47 char buffer[10];
48 scanf("%s ", buffer);
49 num1 = convertString(buffer);
50 scanf("%s ", buffer);
51 num2 = convertString(buffer);
52 for (i = 0; i < 3; i++)
53 {
54 scanf("%s ", buffer);
55 op[i] = buffer[0];
56 }
57 scanf("%s ", buffer);
58 num3 = convertString(buffer);
59
60 return ;
61 } /* FUNCTION getInput */
62
63 int convertString(char string[])
64 {
65 int total = 0;
66 int i;
67
68 for (i = 0; i < strlen(string); i++)
69 {
70 total *= 4;
71
72 switch(string[i])
73 {
74 case 'V':
75 break;
76
77 case 'U':
78 total += 1;
79 break;
80
81 case 'C':
82 total += 2;
83 break;
84
85 case 'D':
86 total += 3;
87 break;
88
89 default:
90 DEBUG fprintf(stderr, "Something went wrong in convertString.\n");
91 break;
92 }
93 }
94
95 return total;
96 }
97
98 void process()
99 {
100 /* FUNCTION process */
101 int i;
102
103 for (i = 0; i < 3; i++)
104 {
105 switch(op[i])
106 {
107 case 'A':
108 num2 = num1 + num2;
109 break;
110 case 'R':
111 num2 = num2 / 4;
112 break;
113 case 'L':
114 num2 = num2 * 4;
115 break;
116 case 'N':
117 break;
118
119 default:
120 DEBUG fprintf(stderr, "Something went wrong in process().\n");
121 break;
122 }
123 }
124 if (num2 == num3)
125 {
126 printf("YES\n");
127 }
128 else
129 {
130 printf("NO\n");
131 }
132 } /* FUNCTION process */
133
134 int main ()
135 {
136 /* main */
137 int i;
138
139 init();
140 printf("COWCULATIONS OUTPUT\n");
141 for (i=0; i<numberOfTimes; i++)
142 {
143 /* while */
144 getInput();
145 process();
146 } /* while */
147 printf("END OF OUTPUT\n");
148
149 return EXIT_SUCCESS;
150 } /* main */
151