/home/toolbox/public_html/solutions/4/417/a.cpp
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 #include <string>
11 #include <map>
12 #include <iostream>
13
14 using namespace std;
15
16 #define TRUE (1 == 1)
17 #define FALSE (1 != 1)
18
19 #define DEBUG if (FALSE)
20
21
22 /*
23 * Author: Isaac Traxler
24 * Date: 2018-09-18
25 * Purpose: fun
26 * Problem: 417
27 */
28
29 /*
30 * This template reads lines of data at a time until end of file.
31 */
32 #define MAX_LINE 10
33
34 std::map<string,int> tbl;
35 char line[MAX_LINE];
36
37 void init()
38 {
39 /* FUNCTION init */
40 int i;
41 int j;
42 int k;
43 int l;
44 int m;
45 int value = 1;
46 char idx[6];
47
48 idx[1] = 0;
49 idx[2] = 0;
50 idx[3] = 0;
51 idx[4] = 0;
52 idx[5] = 0;
53 for (i=0; i<26; i++)
54 {
55 /* do all single letter cases */
56 idx[0] = i + 'a';
57 tbl[idx] = value;
58 value++;
59 } /* do all single letter cases */
60
61 /* 2 chr cases */
62 for (i=0; i<26; i++)
63 {
64 /* do first letter */
65 idx[0] = i + 'a';
66 for (j=i+1; j<26; j++)
67 {
68 /* for second letter */
69 idx[1] = j + 'a';
70 tbl[idx] = value;
71 value++;
72 } /* for second letter */
73 } /* do first letter */
74
75 /* 3 chr cases */
76 for (i=0; 26>i; i++)
77 {
78 /* do first letter */
79 idx[0] = i + 'a';
80 for (j=i+1; 26>j; j++)
81 {
82 /* for second letter */
83 idx[1] = j + 'a';
84 for (k=j+1; 26>k; k++)
85 {
86 /* for 3rd char */
87 idx[2] = k + 'a';
88 tbl[idx] = value;
89 value++;
90 } /* for 3rd char */
91 } /* for second letter */
92 } /* do first letter */
93
94 /* 4 chr cases */
95 for (i=0; 26>i; i++)
96 {
97 /* do first letter */
98 idx[0] = i + 'a';
99 for (j=i+1; 26>j; j++)
100 {
101 /* for second letter */
102 idx[1] = j + 'a';
103 for (k=j+1; 26>k; k++)
104 {
105 /* for 3rd char */
106 idx[2] = k + 'a';
107 for (l=k+1; 26>l; l++)
108 {
109 /* for 4th character */
110 idx[3] = l + 'a';
111 tbl[idx] = value;
112 value++;
113 } /* for 4th character */
114 } /* for 3rd char */
115 } /* for second letter */
116 } /* do first letter */
117
118 /* 5 chr cases */
119 for (i=0; 26>i; i++)
120 {
121 /* do first letter */
122 idx[0] = i + 'a';
123 for (j=i+1; 26>j; j++)
124 {
125 /* for second letter */
126 idx[1] = j + 'a';
127 for (k=j+1; 26>k; k++)
128 {
129 /* for 3rd char */
130 idx[2] = k + 'a';
131 for (l=k+1; 26>l; l++)
132 {
133 /* for 4th character */
134 idx[3] = l + 'a';
135 for (m=l+1; 26>m; m++)
136 {
137 /* for 5 th character */
138 idx[4] = m + 'a';
139 tbl[idx] = value;
140 value++;
141 } /* for 5 th character */
142 } /* for 4th character */
143 } /* for 3rd char */
144 } /* for second letter */
145 } /* do first letter */
146
147 } /* FUNCTION init */
148
149 void dump()
150 {
151 /* FUNCTION dump */
152
153 } /* FUNCTION dump */
154
155 int getInput()
156 {
157 /* FUNCTION getInput */
158 int dataReadFlag;
159
160 fgets(line, MAX_LINE, stdin);
161 if (feof(stdin))
162 dataReadFlag = FALSE;
163 else
164 {
165 /* something to read */
166 line[strlen(line)-1] = 0;
167 dataReadFlag = (0 < strlen(line));
168 } /* something to read */
169 return (dataReadFlag);
170 } /* FUNCTION getInput */
171
172 void process()
173 {
174 /* FUNCTION process */
175 DEBUG printf("line = [%s]\n", line);
176 if (tbl.count(line))
177 {
178 /* found the word */
179 cout << tbl[line] << "\n";
180 } /* found the word */
181 else
182 {
183 /* invalid word */
184 cout << "0\n";
185 } /* invalid word */
186 } /* FUNCTION process */
187
188 int main()
189 {
190 /* main */
191 int moreToDo;
192
193 init();
194 moreToDo = getInput();
195 while (moreToDo)
196 {
197 /* while */
198 process();
199 moreToDo = getInput();
200 } /* while */
201
202 return EXIT_SUCCESS;
203 } /* main */
204