/home/toolbox/public_html/solutions/123/12398/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 #define MAX_LINE 257
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2016-03-15
20 * Purpose: fun
21 * Problem: 12398
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 char line[MAX_LINE];
29 int p[3][3];
30
31 void init()
32 {
33 /* FUNCTION init */
34 int i;
35 int j;
36
37 for (i=0; 3>i; i++)
38 {
39 /* for */
40 for (j=0; 3>j; j++)
41 {
42 /* for */
43 p[i][j] = 0;
44 } /* for */
45 } /* for */
46 } /* FUNCTION init */
47
48 void dump()
49 {
50 /* FUNCTION dump */
51 int i;
52 int j;
53
54 for (i=0; 3>i; i++)
55 {
56 /* for */
57 printf("%d", p[i][0]);
58 for (j=1; 3>j; j++)
59 {
60 /* for */
61 printf(" %d", p[i][j]);
62 } /* for */
63 printf("\n");
64 } /* for */
65 } /* FUNCTION dump */
66
67 int getInput()
68 {
69 /* FUNCTION getInput */
70 int dataReadFlag;
71
72 fgets(line, MAX_LINE, stdin);
73 if (feof(stdin))
74 dataReadFlag = FALSE;
75 else
76 {
77 /* something to read */
78 dataReadFlag = TRUE;
79 line[strlen(line)-1] = 0;
80 } /* something to read */
81 return (dataReadFlag);
82 } /* FUNCTION getInput */
83
84 void process()
85 {
86 /* FUNCTION process */
87 int i;
88
89 for (i=0; strlen(line)>i; i++)
90 {
91 /* for each click */
92 DEBUG printf("Processing [%c]\n", line[i]);
93 switch (line[i])
94 {
95 /* switch */
96 case 'a':
97 p[0][0] = (1 + p[0][0]) % 10; /* start a */
98 p[0][1] = (1 + p[0][1]) % 10; /* right b */
99 p[1][0] = (1 + p[1][0]) % 10; /* below d */
100 break;
101 case 'b':
102 p[0][1] = (1 + p[0][1]) % 10; /* start b */
103 p[0][0] = (1 + p[0][0]) % 10; /* left a */
104 p[0][2] = (1 + p[0][2]) % 10; /* right c */
105 p[1][1] = (1 + p[1][1]) % 10; /* below e */
106 break;
107 case 'c':
108 p[0][2] = (1 + p[0][2]) % 10; /* start c */
109 p[0][1] = (1 + p[0][1]) % 10; /* left b */
110 p[1][2] = (1 + p[1][2]) % 10; /* below f */
111 break;
112 case 'd':
113 p[1][0] = (1 + p[1][0]) % 10; /* start d */
114 p[0][0] = (1 + p[0][0]) % 10; /* above a */
115 p[1][1] = (1 + p[1][1]) % 10; /* right e */
116 p[2][0] = (1 + p[2][0]) % 10; /* below g */
117 break;
118 case 'e':
119 p[1][1] = (1 + p[1][1]) % 10; /* start e */
120 p[0][1] = (1 + p[0][1]) % 10; /* above b */
121 p[1][2] = (1 + p[1][2]) % 10; /* right f */
122 p[2][1] = (1 + p[2][1]) % 10; /* below h */
123 p[1][0] = (1 + p[1][0]) % 10; /* right d */
124 break;
125 case 'f':
126 p[1][2] = (1 + p[1][2]) % 10; /* start f */
127 p[0][2] = (1 + p[0][2]) % 10; /* above c */
128 p[1][1] = (1 + p[1][1]) % 10; /* left e */
129 p[2][2] = (1 + p[2][2]) % 10; /* below i */
130 break;
131 case 'g':
132 p[2][0] = (1 + p[2][0]) % 10; /* start g */
133 p[1][0] = (1 + p[1][0]) % 10; /* above d */
134 p[2][1] = (1 + p[2][1]) % 10; /* right h */
135 break;
136 case 'h':
137 p[2][1] = (1 + p[2][1]) % 10; /* start h */
138 p[1][1] = (1 + p[1][1]) % 10; /* above e */
139 p[2][0] = (1 + p[2][0]) % 10; /* left g */
140 p[2][2] = (1 + p[2][2]) % 10; /* right i */
141 break;
142 case 'i':
143 p[2][2] = (1 + p[2][2]) % 10; /* start i */
144 p[1][2] = (1 + p[1][2]) % 10; /* above f */
145 p[2][1] = (1 + p[2][1]) % 10; /* left h */
146 break;
147 } /* switch */
148 DEBUG dump();
149 } /* for each click */
150 } /* FUNCTION process */
151
152 int main()
153 {
154 /* main */
155 int moreToDo;
156 int cs = 1;
157
158 moreToDo = getInput();
159 while (moreToDo)
160 {
161 /* while */
162 init();
163 printf("Case #%d:\n", cs);
164 cs++;
165 process();
166 dump();
167 moreToDo = getInput();
168 } /* while */
169
170 return EXIT_SUCCESS;
171 } /* main */
172