POJ 2503 Babelfish[字典树]
2012-04-10 18:52
387 查看
Description
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Sample Input
Sample Output
View Code
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Sample Input
dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay
Sample Output
cat eh loops
View Code
#include<stdio.h> #include<string.h> struct node { int count; struct node*next[26]; node() { count=-1; memset(next,0,sizeof(next)); } }; char w[100003][33]; void add(char *a,node* root,int num) { int x,i=0; node*p=root; while(a[i]) { x=a[i]-'a'; if(p->next[x]==NULL) p->next[x]=new node(); p=p->next[x]; i++; } p->count=num; } int find(char *a,node*root) { int x,i=0; node *p=root; while(a[i]) { x=a[i]-'a'; if(p->next[x]==NULL) return -1; p=p->next[x]; i++; } return p->count; } int main() { char s[33]; int i=0; node* root; root=new node(); while(gets(s)&&s[0]!=0) { sscanf(s,"%s %s",w[++i],s); add(s,root,i); } while(scanf("%s",s)!=EOF) { int k=find(s,root); if(k!=-1) printf("%s\n",w[k]); else printf("eh\n"); } return 0; }
相关文章推荐
- POJ 2503 Babelfish map水过,字典树????
- POJ 2503 Babelfish(字典树Trie)
- poj 2503 Babelfish(字典树或着STL)
- POJ 2503 Babelfish (字典树)
- 文章标题 POJ 2503 : Babelfish(字典树)
- poj 2503 Babelfish(字典树)
- POJ 2503 Babelfish(STL、二分、字典树、哈希)
- POJ 2503 Babelfish(字典树水题)
- poj 2503:Babelfish(字典树,经典题,字典翻译)
- POJ 2503 Babelfish(字典树)
- POJ 2503 - Babelfish(字典树)
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
- poj 2503 Babelfish(字典树哈希)
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
- POJ - 2503 - Babelfish(字典树)
- poj 2503 Babelfish(字典树或map或哈希或排序二分)
- POJ_2503_Babelfish【字典树】
- POJ 2503 Babelfish 字典树
- poj 2503 Babelfish(字典树)
- POJ 2503 Babelfish 字典树应用