Poj:2503 Babelfish
2016-07-06 20:54
585 查看
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
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
Sample Output
cat
eh
loops
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
#include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; const int maxn=100009; struct trie { int next[32]; char str[26]; void init() { memset(next,0,sizeof(next)); memset(str,0,sizeof(str)); } }tree[maxn*2]; int index; void insert(char *s,char *t) { int len=strlen(s); int p=0; for(int i=0;i<len;i++) { int x=s[i]-'a'; if(tree[p].next[x]==0) tree[p].next[x]=++index; p=tree[p].next[x]; } memcpy(tree[p].str,t,strlen(t)); } void find(char *s) { int len=strlen(s); int p=0; for(int i=0;i<len;i++) { int x=s[i]-'a'; if(tree[p].next[x]==0) {printf("eh\n"); return; } p=tree[p].next[x]; } printf("%s\n",tree[p].str); } int main() { char st[32]; while(gets(st)&&st[0]) { char str[22],ste[22]; int len=strlen(st); int i,j; for(i=0;st[i]!=' ';i++) str[i]=st[i]; str[i]='\0'; for(i=i+1,j=0;i<len;j++,i++) ste[j]=st[i]; ste[j]='\0'; //printf("%s %s\n",str,ste); insert(ste,str); } char ss[12]; while(gets(ss)) find(ss); return 0; }
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2159 Ancient Cipher
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- [数论]poj2635__The Embarrassed Cryptographer
- [二分图匹配]poj2446__Chessboard
- POJ1050 最大子矩阵和
- 用单调栈解决最大连续矩形面积问题