/home/toolbox/public_html/solutions/4/494/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 #define MAX_LINE 200
16 #define WORD 1
17 #define START 0
18
19 /*
20 * Author: Isaac Traxler
21 * Date: 2014-10-28
22 * Purpose: fun
23 * Problem: 494 - Kindergarten Counting Games
24 */
25
26 /*
27 * This template reads data until a terminating value is reached.
28 */
29
30 char line[MAX_LINE];
31
32 void init()
33 {
34 /* FUNCTION init */
35 } /* FUNCTION init */
36
37 void dump()
38 {
39 /* FUNCTION dump */
40 } /* FUNCTION dump */
41
42 int getInput()
43 {
44 /* FUNCTION getInput */
45 int dataReadFlag;
46
47 fgets(line, MAX_LINE, stdin);
48 if (feof(stdin))
49 dataReadFlag = FALSE;
50 else
51 {
52 /* something to read */
53 dataReadFlag = TRUE;
54 line[strlen(line)-1] = 0;
55 } /* something to read */
56 return (dataReadFlag);
57 } /* FUNCTION getInput */
58
59 void process()
60 {
61 /* FUNCTION process */
62 int i;
63 int state = START;
64 int cnt = 0;
65
66 for (i=0; i<strlen(line); i++)
67 {
68 /* process each char */
69 DEBUG printf("state=%d char=[%c] cnt=%d\n", state, line[i], cnt);
70 if (isalpha(line[i]))
71 {
72 /* found a letter */
73 if (WORD != state)
74 {
75 /* found beginning of a new word */
76 cnt ++;
77 state = WORD;
78 } /* found beginning of a new word */
79 } /* found a letter */
80 else
81 state = START;
82 } /* process each char */
83 printf("%d\n", cnt);
84 } /* FUNCTION process */
85
86 int main ()
87 {
88 /* main */
89 int moreToDo;
90
91 init();
92 moreToDo = getInput();
93 while (moreToDo)
94 {
95 /* while */
96 process();
97 moreToDo = getInput();
98 } /* while */
99
100 return EXIT_SUCCESS;
101 } /* main */
102