-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy path10282.cpp
More file actions
executable file
·74 lines (57 loc) · 1.14 KB
/
10282.cpp
File metadata and controls
executable file
·74 lines (57 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* UVA: Babelfish prob: 10282
Programmer: Md. Mahmud Ahsan
Visual C++ 6
IN Lab
*/
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct dic{
char foreign[12];
char english[12];
}dict[100005];
int bSearch(char *str, int max){
int mid, low, high, cmp;
low = 0;
high = max;
while (low <= high){
mid = (low + high) / 2;
cmp = strcmp(dict[mid].foreign, str);
if (cmp == 0)
return mid;
else if (cmp > 0)
high = mid - 1;
else
low = mid + 1;
}
return -1;
}
int cmp(const void *a, const void *b){
dic *x, *y;
x = (dic*) a;
y = (dic*) b;
return strcmp(x->foreign, y->foreign);
}
int main(){
freopen("input.txt", "r", stdin);
int i = 0, j;
char str[100], a[100], b[100];
while(gets(str)){
if (strlen(str) == 0) break;
sscanf(str, "%s %s", a, b);
strcpy(dict[i].english, a);
strcpy(dict[i].foreign, b);
++i;
}
qsort(dict, i, sizeof(dict[0]), cmp);
while (cin >> str){
j = bSearch(str, i);
if (j >= 0)
cout << dict[j].english << endl;
else
cout << "eh" << endl;
}
return 0;
}