/home/toolbox/public_html/solutions/5/514/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 /*
16 * Author: Isaac Traxler
17 * Date: 2015-03-30
18 * Purpose:
19 * Problem: 514
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define STACK_SIZE 1100
27
28 int stack[STACK_SIZE];
29 int top;
30
31 int cars;
32
33 void init()
34 {
35 /* FUNCTION init */
36 } /* FUNCTION init */
37
38 void dump()
39 {
40 /* FUNCTION dump */
41 } /* FUNCTION dump */
42
43 int inspect()
44 {
45 /* FUNCTION inspect */
46 int toReturn;
47
48 if (0 == top)
49 {
50 /* stack empty */
51 toReturn = -1;
52 } /* stack empty */
53 else
54 toReturn = stack[top];
55 return toReturn;
56 } /* FUNCTION inspect */
57
58 int pop()
59 {
60 /* FUNCTION pop */
61 return stack[top--];
62 } /* FUNCTION pop */
63
64 void push(int x)
65 {
66 /* FUNCTION push */
67 stack[top++] = x;
68 } /* FUNCTION push */
69
70 int getInput()
71 {
72 /* FUNCTION getInput */
73 int dataReadFlag;
74
75 scanf(" %d ", &cars);
76 dataReadFlag = (0 != cars);
77 return (dataReadFlag);
78 } /* FUNCTION getInput */
79
80 void process()
81 {
82 /* FUNCTION process */
83 int car;
84 int nxt;
85 int success = TRUE;
86
87 car = 1;
88 top = 0;
89 scanf(" %d ", &nxt);
90 if (0 != nxt)
91 {
92 /* valid case to analyze */
93 while (car <= cars)
94 {
95 /* while more cars to process */
96 if (car == nxt)
97 {
98 /* current car matches desired car */
99 car++;
100 scanf(" %d ", &nxt);
101 } /* current car matches desired car */
102 else
103 {
104
105 }
106 } /* while more cars to process */
107 } /* valid case to analyze */
108
109
110
111 if (0 != nxt)
112 {
113 /* have a case */
114 while (car <= cars)
115 {
116 /* while */
117 printf("car = %d nxt = %d top = %d\n", car, nxt, top);
118 if (car == nxt)
119 {
120 /* car is the next one wanted */
121 car++;
122 } /* car is the next one wanted */
123 else if (car > nxt)
124 {
125 /* desired car must be on stack */
126 if (nxt == inspect())
127 {
128 /* car on top is one we want */
129 pop();
130 } /* car on top is one we want */
131 else
132 {
133 /* not here -- impossible */
134 success = FALSE;
135 while (car < cars)
136 {
137 /* clear rest of cars */
138 scanf(" %d ", &nxt);
139 car++;
140 } /* clear rest of cars */
141 } /* not here -- impossible */
142
143 } /* desired car must be on stack */
144 else
145 {
146 /* car < nxt */
147 while (car <= nxt)
148 {
149 /* while */
150 push(car);
151 car++;
152 } /* while */
153 } /* car < nxt */
154 scanf(" %d ", &nxt);
155 } /* while */
156 } /* have a case */
157 if (success)
158 {
159 printf("Yes");
160 }
161 else
162 {
163 printf("No");
164 }
165 printf("\n");
166 } /* FUNCTION process */
167
168 int main()
169 {
170 /* main */
171 int moreToDo;
172
173 init();
174 moreToDo = getInput();
175 while (moreToDo)
176 {
177 /* while */
178 process();
179 moreToDo = getInput();
180 } /* while */
181
182 return EXIT_SUCCESS;
183 } /* main */
184
185
186
187
188