POJ 2503 Babelfish
来源:互联网 发布:stc12单片机选型 编辑:程序博客网 时间:2024/05/29 17:24
Babelfish
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 26214 Accepted: 11249
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 ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Sample Output
catehloops
Hint
Huge input and output,scanf and printf are recommended.
Source
Waterloo local 2001.09.22
考察点:字典树
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;struct Tire{ struct Tire* next[26]; int tag;};char s1[100010][15],s2[15];int main(){ struct Tire *newnode(); void build(char s[15],int k,struct Tire *p); int find(char s[15],struct Tire *p); struct Tire *head; int i,j,n,m,s,t,k; t=1; head=newnode(); while(1) { gets(s2); if(strlen(s2)==0) { break; } for(i=0,j=0;i<=strlen(s2)-1;i++) { if(s2[i]!=' ') { s1[t][j++]=s2[i]; }else { break; } } s1[t][j]='\0'; for(i=i+1,j=0;i<=strlen(s2)-1;i++) { s2[j]=s2[i]; j++; } s2[j]='\0'; build(s2,t,head); t++; } while(scanf("%s",s2)!=EOF) { k=find(s2,head); if(k==0) { printf("eh\n"); }else { printf("%s\n",s1[k]); } } return 0;}struct Tire* newnode(){ struct Tire *p; p=new(struct Tire); for(int i=0;i<=25;i++) { p->next[i]=NULL; } p->tag=0; return p;}void build(char s[15],int k,struct Tire *p){ int a; for(int i=0;i<=strlen(s)-1;i++) { a=s[i]-'a'; if(p->next[a]==NULL) { p->next[a]=newnode(); } p=p->next[a]; } p->tag=k;}int find(char s[15],struct Tire *p){ int a; for(int i=0;i<=strlen(s)-1;i++) { a=s[i]-'a'; if(p->next[a]!=NULL) { p=p->next[a]; }else { return 0; } } return p->tag;}
- poj 2503 Babelfish
- POJ 2503 Babelfish(HASH)
- poj 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish 【hash】
- poj 2503 Babelfish【trie】
- POJ 2503 Babelfish
- poj-2503 Babelfish
- poj-2503 Babelfish
- poj 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish (Hash)
- POJ 2503 Babelfish
- poj 2503 Babelfish(二分)
- windows考试复习题“填空+简答”
- apk签名
- getParameter()的参数问题
- Linux系统中程序库文件简介
- nexus 7 4.2 没有开发者选项
- POJ 2503 Babelfish
- 如何定位c++内存泄露
- Linux Commands
- ios横竖屏问题
- .NET 序列化与反序化
- 常见oracle错误汇总
- 怎样设置locale
- 进制转换与称重问题
- Flash Builder实用快捷键集锦