/home/toolbox/public_html/solutions/121/12195/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 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2021-11-05
19 * Purpose: fun
20 * Problem: 12195 - Jingle Composing
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 #define MAX_LINE 210
28 /* A (65) ( 0)
29 * W (87) (22) 64
30 * H (72) ( 7) 32
31 * Q (81) (16) 16
32 * E (69) ( 4) 8
33 * S (83) (18) 4
34 * T (84) (19) 2
35 * X (88) (23) 1
36 */
37
38 #define WV 64
39 #define HV 32
40 #define QV 16
41 #define EV 8
42 #define SV 4
43 #define TV 2
44 #define XV 1
45
46 #define W 22
47 #define H 7
48 #define Q 16
49 #define E 4
50 #define S 18
51 #define T 19
52 #define X 23
53
54 #define MEASURE 64
55
56
57 char line[MAX_LINE];
58 int notes[26];
59
60 void init()
61 {
62 /* FUNCTION init */
63 int i;
64
65 for (i=0; 26>i; i++)
66 {
67 notes[i] = 0;
68 }
69 notes[W] = WV;
70 notes[H] = HV;
71 notes[Q] = QV;
72 notes[E] = EV;
73 notes[S] = SV;
74 notes[T] = TV;
75 notes[X] = XV;
76 } /* FUNCTION init */
77
78 void dump()
79 {
80 /* FUNCTION dump */
81 } /* FUNCTION dump */
82
83 int getInput()
84 {
85 /* FUNCTION getInput */
86 int dataReadFlag;
87
88 scanf(" %s ", line);
89 dataReadFlag = ('*' != line[0]);
90 return (dataReadFlag);
91 } /* FUNCTION getInput */
92
93 void process()
94 {
95 /* FUNCTION process */
96 int tot;
97 int cnt;
98 int lineLen;
99 int i;
100
101 lineLen = strlen(line);
102 i = 1;
103 cnt = 0;
104 tot = 0;
105 while (i < lineLen)
106 {
107 /* while more to do */
108 while ('/' != line[i])
109 {
110 /* process measure */
111 tot = tot + notes[line[i]-'A'];
112 i++;
113 } /* process measure */
114 DEBUG printf("(i %d) (tot %d) cnt %d)\n", i, tot, cnt);
115 if (MEASURE == tot)
116 {
117 /* found a valid measure */
118 cnt++;
119 } /* found a valid measure */
120 tot = 0;
121 i++;
122 } /* while more to do */
123 printf("%d\n", cnt);
124 } /* FUNCTION process */
125
126 int main()
127 {
128 /* main */
129 int moreToDo;
130
131 init();
132 moreToDo = getInput();
133 while (moreToDo)
134 {
135 /* while */
136 process();
137 moreToDo = getInput();
138 } /* while */
139
140 return EXIT_SUCCESS;
141 } /* main */
142