博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2503 Babelfish 字典树
阅读量:6155 次
发布时间:2019-06-21

本文共 2822 字,大约阅读时间需要 9 分钟。

Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 24994   Accepted: 10703

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
1 /* 功能Function Description:     POJ-2503  字典树 2    开发环境Environment:          DEV C++ 4.9.9.1 3    技术特点Technique: 4    版本Version: 5    作者Author:                   可笑痴狂 6    日期Date:                      20120810 7    备注Notes: 8         注意输入格式的控制 9 */10 #include
11 #include
12 #include
13 14 typedef struct node15 {16 char s[20];17 struct node *next[26];18 }node;19 20 void insert(char *a,char *b,node *T)21 {22 node *p,*q;23 int i,j,id;24 p=T;25 i=0;26 while(b[i])27 {28 id=b[i]-'a';29 if(p->next[id]==NULL)30 {31 q=(node *)malloc(sizeof(node));32 memset(q->s,'\0',sizeof(q->s));33 for(j=0;j<26;++j)34 q->next[j]=NULL;35 p->next[id]=q;36 }37 p=p->next[id];38 ++i;39 }40 strcpy(p->s,a);41 }42 43 void search(char *a,node *T)44 {45 int id,i=0;46 node *p=T;47 while(a[i])48 {49 id=a[i]-'a';50 if(p->next[id]==NULL)51 {52 printf("eh\n");53 return;54 }55 p=p->next[id];56 ++i;57 }58 if((p->s)[0]!='\0')59 printf("%s\n",p->s);60 else61 printf("eh\n");62 }63 64 int main()65 {66 char a[20],b[20];67 char c[40];68 node *T;69 int i,len,k;70 T=(node *)malloc(sizeof(node));71 memset(T->s,'\0',sizeof(T->s));72 for(i=0;i<26;++i)73 T->next[i]=NULL;74 while(gets(c)&&c[0]!='\0') //注意输入格式,输入空行时结束while循环75 {76 len=strlen(c);77 for(i=0;c[i]!=' ';++i)78 a[i]=c[i];79 a[i]='\0';80 for(++i,k=0;i<=len;++i)81 b[k++]=c[i];82 insert(a,b,T);83 }84 while(scanf("%s",a)!=EOF)85 {86 search(a,T);87 }88 return 0;89 }

 

 

转载地址:http://fgifa.baihongyu.com/

你可能感兴趣的文章
跨域-学习笔记
查看>>
the assignment of reading paper
查看>>
android apk 逆向中常用工具一览
查看>>
MyEclipse 报错 Errors running builder 'JavaScript Validator' on project......
查看>>
Skip List——跳表,一个高效的索引技术
查看>>
Yii2单元测试初探
查看>>
五、字典
查看>>
前端js之JavaScript
查看>>
Log4J日志配置详解
查看>>
实验7 BindService模拟通信
查看>>
scanf
查看>>
Socket编程注意接收缓冲区大小
查看>>
SpringMVC初写(五)拦截器
查看>>
检测oracle数据库坏块的方法
查看>>
SQL server 安装教程
查看>>
Linux下ftp和ssh详解
查看>>
跨站脚本功攻击,xss,一个简单的例子让你知道什么是xss攻击
查看>>
js时间和时间戳之间如何转换(汇总)
查看>>
js插件---图片懒加载echo.js结合 Amaze UI ScrollSpy 使用
查看>>
java中string和int的相互转换
查看>>