/home/toolbox/public_html/solutions/102/10282/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: 10282
27 */
28
29 /*
30 * This template reads lines of data at a time until end of file.
31 */
32 #define MAX_LINE 30
33
34 char line[MAX_LINE];
35 std::map<string,string> dct;
36
37 void init()
38 {
39 /* FUNCTION init */
40 char eng[MAX_LINE];
41 char frg[MAX_LINE];
42 int i;
43 int j;
44
45 fgets(line, MAX_LINE, stdin);
46 line[strlen(line)-1] = 0;
47 while (0 < strlen(line))
48 {
49 /* load dictionary */
50 for (i=0; (' ' != line[i]); i++)
51 {
52 /* grab first word */
53 eng[i] = line[i];
54 } /* grab first word */
55 eng[i] = '\0';
56 i++;
57 for (j=0; strlen(line)>i; i++,j++)
58 {
59 /* get second word */
60 frg[j] = line[i];
61 } /* get second word */
62 frg[j] = '\0';
63 dct[frg] = eng;
64 DEBUG printf("[%s] [%s] [%s] dct[%s] = ", line, eng, frg, frg);
65 DEBUG cout << "(" << dct[frg] << ")\n";
66 fgets(line, MAX_LINE, stdin);
67 line[strlen(line)-1] = 0;
68 } /* load dictionary */
69
70 } /* FUNCTION init */
71
72 void dump()
73 {
74 /* FUNCTION dump */
75 } /* FUNCTION dump */
76
77 int getInput()
78 {
79 /* FUNCTION getInput */
80 int dataReadFlag;
81
82 fgets(line, MAX_LINE, stdin);
83 if (feof(stdin))
84 dataReadFlag = FALSE;
85 else
86 {
87 /* something to read */
88 dataReadFlag = TRUE;
89 line[strlen(line)-1] = 0;
90 } /* something to read */
91 return (dataReadFlag);
92 } /* FUNCTION getInput */
93
94 void process()
95 {
96 /* FUNCTION process */
97 if (dct.count(line))
98 {
99 /* found the word */
100 cout << dct[line] << "\n";
101 } /* found the word */
102 else
103 {
104 /* invalid word */
105 cout << "eh\n";
106 } /* invalid word */
107 } /* FUNCTION process */
108
109 int main()
110 {
111 /* main */
112 int moreToDo;
113
114 init();
115 moreToDo = getInput();
116 while (moreToDo)
117 {
118 /* while */
119 process();
120 moreToDo = getInput();
121 } /* while */
122
123 return EXIT_SUCCESS;
124 } /* main */
125