/home/toolbox/public_html/solutions/17/1727/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 <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /* fprintf(stderr, "functionName: message", varslist); */
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2018-11-14
20 * Purpose: fun
21 * Problem: 1727
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 #define SUN ('S' * 100 + 'U')
29 #define MON ('M' * 100 + 'O')
30 #define TUE ('T' * 100 + 'U')
31 #define WED ('W' * 100 + 'E')
32 #define THU ('T' * 100 + 'H')
33 #define FRI ('F' * 100 + 'R')
34 #define SAT ('S' * 100 + 'A')
35
36 int numberOfTimes;
37 char mnth[10];
38 char day[10];
39
40 void init()
41 {
42 /* FUNCTION init */
43 scanf("%d ", &numberOfTimes);
44 } /* FUNCTION init */
45
46 void dump()
47 {
48 /* FUNCTION dump */
49 } /* FUNCTION dump */
50
51 int daysInMonth()
52 {
53 /* FUNCTION daysInMonth */
54 int ret = 31;
55
56 DEBUG printf("mnth %s ret(%d)", mnth, ret);
57 switch (mnth[0])
58 {
59 /* switch */
60 /* January, June, July */
61 case 'J':
62 if (('U' == mnth[1]) && ('N' == mnth[2]))
63 {
64 ret = 30; /* June */
65 }
66 break;
67 /* February */
68 case 'F':
69 ret = 28;
70 break;
71 /* March, May */
72 case 'M':
73 ret = 31;
74 break;
75 /* April, August */
76 case 'A':
77 if ('P' == mnth[1])
78 {
79 ret = 30; /* april else august */
80 }
81 break;
82 /* September */
83 case 'S':
84 ret = 30;
85 break;
86 /* October */
87 case 'O':
88 ret = 31;
89 break;
90 /* November */
91 case 'N':
92 ret = 30;
93 break;
94 /* December */
95 case 'D':
96 ret = 31;
97 break;
98 } /* switch */
99 DEBUG printf(" ret(%d)\n", ret);
100 return ret;
101 } /* FUNCTION daysInMonth */
102
103 void getInput()
104 {
105 /* FUNCTION getInput */
106 scanf(" %s %s ", mnth, day);
107 } /* FUNCTION getInput */
108
109 int computeDay()
110 {
111 /* FUNCTION computeDay */
112 int ret = -1;
113
114 switch ((day[0] * 100) + day[1])
115 {
116 /* switch */
117 case SUN:
118 ret = 0;
119 break;
120 case MON:
121 ret = 1;
122 break;
123 case TUE:
124 ret = 2;
125 break;
126 case WED:
127 ret = 3;
128 break;
129 case THU:
130 ret = 4;
131 break;
132 case FRI:
133 ret = 5;
134 break;
135 case SAT:
136 ret = 6;
137 break;
138 } /* switch */
139 return ret;
140 } /* FUNCTION computeDay */
141
142 void process()
143 {
144 /* FUNCTION process */
145 int mx;
146 int cnt;
147 int dy;
148
149 mx = daysInMonth();
150 if (28 == mx)
151 {
152 printf("8\n"); /* feb is always 8 weekend days */
153 }
154 else
155 {
156 /* 30 or 31 days */
157 dy = computeDay();
158 if (30 == mx)
159 {
160 /* 30 days */
161 switch (dy)
162 {
163 /* what was first day */
164 case 0:
165 cnt = 8;
166 break;
167 case 1:
168 cnt = 8;
169 break;
170 case 2:
171 cnt = 8;
172 break;
173 case 3:
174 cnt = 8;
175 break;
176 case 4:
177 cnt = 9;
178 break;
179 case 5:
180 cnt = 10;
181 break;
182 case 6:
183 cnt = 9;
184 break;
185 } /* what was first day */
186 } /* 30 days */
187 else
188 {
189 /* 31 days */
190 switch (dy)
191 {
192 /* what was first day */
193 case 0:
194 cnt = 8;
195 break;
196 case 1:
197 cnt = 8;
198 break;
199 case 2:
200 cnt = 8;
201 break;
202 case 3:
203 cnt = 9;
204 break;
205 case 4:
206 cnt = 10;
207 break;
208 case 5:
209 cnt = 10;
210 break;
211 case 6:
212 cnt = 9;
213 break;
214 } /* what was first day */
215 } /* 31 days */
216 DEBUG printf("mnth %s mx(%d) day %s dy(%d)\n", mnth, mx, day, dy);
217 printf("%d\n", cnt);
218 } /* 30 or 31 days */
219
220 } /* FUNCTION process */
221
222 int main()
223 {
224 /* main */
225 int i;
226
227 init();
228 for (i=0; i<numberOfTimes; i++)
229 {
230 /* while */
231 getInput();
232 process();
233 } /* while */
234
235 return EXIT_SUCCESS;
236 } /* main */
237
238