/home/toolbox/public_html/solutions/7/700/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 /*
16 * Author: Isaac Traxler
17 * Date: 2015-0403
18 * Purpose:
19 * Problem: 700
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define MAX_COMPUTERS 21
27 #define MAX_YEARS 10000
28
29 typedef struct COMPUTER_STRUCT
30 {
31 int display;
32 int built;
33 int wrap;
34 }
35 COMPUTER_STRUCT;
36
37 COMPUTER_STRUCT comp[MAX_COMPUTERS];
38 int compCnt;
39
40 void init()
41 {
42 /* FUNCTION init */
43 } /* FUNCTION init */
44
45 void dump()
46 {
47 /* FUNCTION dump */
48 } /* FUNCTION dump */
49
50 int getInput()
51 {
52 /* FUNCTION getInput */
53 int dataReadFlag;
54 int i;
55
56 scanf(" %d ", &compCnt);
57 dataReadFlag = (0 != compCnt);
58 if (dataReadFlag)
59 {
60 /* load computer data */
61 for (i=0; i<compCnt; i++)
62 {
63 /* for */
64 scanf(" %d %d %d ", &comp[i].display, &comp[i].built, &comp[i].wrap);
65 } /* for */
66 } /* load computer data */
67 return (dataReadFlag);
68 } /* FUNCTION getInput */
69
70 void solve()
71 {
72 /* FUNCTION solve */
73 int i;
74 int j;
75 int inc;
76 unsigned char years[MAX_YEARS] = {0};
77 int flag = FALSE;
78
79 for (i=0; i<compCnt; i++)
80 {
81 /* for */
82 inc = comp[i].wrap - comp[i].built;
83 for (j=comp[i].display; j<MAX_YEARS; j=j+inc)
84 {
85 /* for j */
86 years[j]++;
87 } /* for j */
88 } /* for */
89
90 /* now see if an answer exists */
91 for (i=0; (! flag) && (i<MAX_YEARS); i++)
92 {
93 /* for */
94 flag = (compCnt == years[i]);
95 } /* for */
96 if (flag)
97 {
98 /* found an answer */
99 printf("The actual year is %d.\n", i-1);
100 } /* found an answer */
101 else
102 {
103 /* no definitive answer */
104 printf("Unknown bugs detected.\n");
105 } /* no definitive answer */
106
107 } /* FUNCTION solve */
108
109 void process()
110 {
111 /* FUNCTION process */
112 int i;
113 int match = TRUE;;
114 int tmp;
115
116 tmp = comp[0].display;
117 for (i=1; i<compCnt; i++)
118 {
119 /* for */
120 match = match && (tmp == comp[i].display);
121 } /* for */
122 if (match)
123 printf("The actual year is %d.\n", tmp);
124 else
125 {
126 /* at least one clock different */
127 solve();
128 } /* at least one clock different */
129
130 } /* FUNCTION process */
131
132 int main()
133 {
134 /* main */
135 int moreToDo;
136 int cnt = 1;
137
138 moreToDo = getInput();
139 while (moreToDo)
140 {
141 /* while */
142 printf("Case #%d:\n", cnt);
143 cnt++;
144 process();
145 printf("\n");
146 moreToDo = getInput();
147 } /* while */
148
149 return EXIT_SUCCESS;
150 } /* main */
151