/home/toolbox/public_html/solutions/1/101/c.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 256
16
17 #define MOVE 0
18 #define PILE 1
19 #define ONTO 2
20 #define OVER 3
21
22 #define MAX_BLOCKS 30
23
24 /*
25 * Author: Isaac Traxler
26 * Date: 2014-10-30
27 * Purpose: fun
28 * Problem: 101 - The Blocks Problem
29 */
30
31 /*
32 * This template reads data until a terminating value is reached.
33 */
34
35 int size;
36 char line[MAX_LINE];
37 int cmd;
38 int a;
39 int b;
40 int blocks[MAX_BLOCKS][MAX_BLOCKS];
41
42
43 void dump()
44 {
45 /* FUNCTION dump */
46 } /* FUNCTION dump */
47
48 int getInput()
49 {
50 /* FUNCTION getInput */
51 int dataReadFlag;
52
53 fgets(line, MAX_LINE, stdin);
54 line[strlen(line)-1] = 0;
55 dataReadFlag = 'q' != line[0];
56 return (dataReadFlag);
57 } /* FUNCTION getInput */
58
59 void clean()
60 {
61 /* FUNCTON clean */
62 int i;
63
64 for (i=0; i<strlen(line); i++)
65 {
66 /* for each char */
67 if (! isdigit(line[i]))
68 {
69 line[i] = ' ';
70 }
71 } /* for each char */
72 } /* FUNCTON clean */
73
74 void init()
75 {
76 /* FUNCTION init */
77 int i;
78 int j;
79
80 fgets(line, MAX_LINE, stdin);
81 sscanf(line, " % d ", size);
82 for (i=0; i<size; i++)
83 {
84 /* for each i */
85 blocks[i][0] = 1;
86 blocks[i][1] = i;
87 for (j=2; j<size; j++)
88 {
89 /* for each j */
90 blocks[i][j] = 0;
91 } /* for each j */
92 } /* for each i */
93 } /* FUNCTION init */
94
95 void parseLine()
96 {
97 /* FUNCTION parseLine */
98
99 if (NULL == strstr(line, "move"))
100 cmd = MOVE;
101 else
102 cmd = PILE;
103
104 if (NULL == strstr(line, "over"))
105 cmd = cmd + OVER;
106 else
107 cmd = cmd + ONTO;
108
109 clean();
110 sscanf(line, " %d %d ", &a, &b);
111 } /* FUNCTION parseLine */
112
113 int fnd(int f)
114 {
115 /* FUNCTION fnd */
116 int ret = -1;
117 int i;
118 int j;
119
120 while (-1 = ret)
121 {
122 /* while */
123 for (i=0; i<size; i++)
124 {
125 /* look in each column */
126 for (j=0; j<blocks[i][0]; j++)
127 {
128 /* for each stack */
129
130 } /* for each stack */
131 } /* look in each column */
132 } /* while */
133
134 } /* FUNCTION fnd */
135
136 void process()
137 {
138 /* FUNCTION process */
139 parseLine();
140
141 if ((a != b)) ;
142 switch (cmd)
143 {
144 /* switch */
145 case MOVE+OVER:
146 {
147 /* MOVER + OVER */
148 pa = fnd(a);
149 clear(pa, a);
150 pb = fnd(b);
151 clear(pb, b);
152 remove(a, pa);
153 add(a, pb);
154 break;
155 } /* MOVER + OVER */
156 case MOVE+ONTO:
157 {
158 /* MOVER + ONTO */
159 break;
160 } /* MOVER + ONTO */
161 case PILE+OVER:
162 {
163 /* PILE + OVER */
164 break;
165 } /* PILE + OVER */
166 case PILE+ONTO:
167 {
168 /* PILE + ONTO */
169 break;
170 } /* PILE + ONTO */
171 } /* switch */
172
173 } /* FUNCTION process */
174
175 int main ()
176 {
177 /* main */
178 int moreToDo;
179
180 init();
181 moreToDo = getInput();
182 while (moreToDo)
183 {
184 /* while */
185 process();
186 moreToDo = getInput();
187 } /* while */
188
189 return EXIT_SUCCESS;
190 } /* main */
191