Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cctype>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int i = 0, flag = 0;
- struct dictionary
- {
- char entry[12];
- char foreign[12];
- };
- struct dictionary ar[100010];
- int compare(const void *a, const void *b)
- {
- char str[30], str2[30];
- strcpy(str, ((dictionary *)a)->foreign);
- strcpy(str2, ((dictionary *)b)->foreign);
- if (strcmp(str, str2) > 0) return 1;
- return -1;
- }
- int binsearch(char str[15])
- {
- int j, l, a, b, x = 0, y, z;
- y = -1, a = 0, b = i;
- for (; ;)
- {
- y = (a + b) / 2;
- if (y == x) return x;
- x = y;
- z = strcmp(ar[x].foreign, str);
- if (z == 0) {flag = 1; return x;}
- else if (z < 0) a = x;
- else b = x;
- }
- }
- int main()
- {
- int t, j, k, l, a, b, c, d, x, y, z;
- char str[100];
- for (; ;)
- {
- gets(str);
- if (str[0] == 0) break;
- for (j = 0; str[j] != 32; j++) ar[i].entry[j] = str[j];
- ar[i].entry[j] = 0, j++, l = 0;
- for (; str[j] != 0; j++) ar[i].foreign[l++] = str[j];
- ar[i++].foreign[l] = 0;
- }
- qsort(ar, i, sizeof(dictionary), compare);
- while (gets(str))
- {
- flag = 0;
- z = binsearch(str);
- if (flag == 1) puts(ar[z].entry);
- else puts("eh");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement