/home/toolbox/public_html/solutions/115/11530/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: 2017-09-27
20 * Purpose: fun
21 * Problem: 11530 - SMS Typing
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 #define MAX_BUFFER_LENGTH 105
29
30 int numberOfTimes;
31 int count[128];
32 char buff[MAX_BUFFER_LENGTH];
33
34 void init()
35 {
36 /* FUNCTION init */
37 int i;
38
39 fgets(buff, MAX_BUFFER_LENGTH, stdin);
40 sscanf(buff, " %d ", &numberOfTimes);
41 count[' '] = 1;
42 count['a'] = 1;
43 count['b'] = 2;
44 count['c'] = 3;
45 count['d'] = 1;
46 count['e'] = 2;
47 count['f'] = 3;
48 count['g'] = 1;
49 count['h'] = 2;
50 count['i'] = 3;
51 count['j'] = 1;
52 count['k'] = 2;
53 count['l'] = 3;
54 count['m'] = 1;
55 count['n'] = 2;
56 count['o'] = 3;
57 count['p'] = 1;
58 count['q'] = 2;
59 count['r'] = 3;
60 count['s'] = 4;
61 count['t'] = 1;
62 count['u'] = 2;
63 count['v'] = 3;
64 count['w'] = 1;
65 count['x'] = 2;
66 count['y'] = 3;
67 count['z'] = 4;
68 /*
69 | | abc | def |
70 | ghi | jkl | mno |
71 | pqrs | tuv | wxyz |
72 */
73 } /* FUNCTION init */
74
75 void dump()
76 {
77 /* FUNCTION dump */
78 } /* FUNCTION dump */
79
80 void getInput()
81 {
82 /* FUNCTION getInput */
83 fgets(buff, MAX_BUFFER_LENGTH, stdin);
84 buff[strlen(buff)-1] = '\0'; /* take care of newline */
85 } /* FUNCTION getInput */
86
87 void process()
88 {
89 /* FUNCTION process */
90 int i;
91 int tot = 0;
92
93 for (i=0; strlen(buff) > i; i++)
94 {
95 /* for each character */
96 tot = tot + count[buff[i]];
97 } /* for each character */
98 printf("%d\n", tot);
99 } /* FUNCTION process */
100
101 int main()
102 {
103 /* main */
104 int i;
105
106 init();
107 for (i=1; i<=numberOfTimes; i++)
108 {
109 /* while */
110 getInput();
111 printf("Case #%d: ", i);
112 process();
113 } /* while */
114
115 return EXIT_SUCCESS;
116 } /* main */
117
118