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