poj-2503 Babelfish
来源:互联网 发布:网络摄像头拓扑图 编辑:程序博客网 时间:2024/06/08 14:36
F -Babelfish
Crawling in process...Crawling failedTime Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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
先定义一个结构体用来储存字典,然后对字典中的英文进行排序,输入单词,进行查找,若找到,输出相对应的英文,若找不到则就输出eh.
#include<stdio.h> #include<string.h> #include<stdlib.h> struct diction{ char eng[11]; char fn[11];}; struct diction a[1000001]; int fcmp(const void * a,const void *b){ return strcmp(((diction*)a)->fn, ((diction*)b)->fn); } int cmp(const void* a, const void* b) { return strcmp((char*)a, ((diction*)b)->fn); } int main() { int i,j,k,sum,sign,len; char str[30]; struct diction *p; sum=0; sign=0; while(gets(str)) { len=strlen(str); if(len==0) break; else { for(i=0;i<len;i++) { if(str[i]==' ') break; a[sum].eng[i]=str[i]; } a[sum].eng[i]='\0'; for(j=i+1,k=0;j<len;j++,k++) a[sum].fn[k]=str[j]; a[sum].fn[k]='\0'; sum++; } } qsort(a,sum,sizeof(diction),fcmp); while(gets(str)) { p=(diction*)bsearch(str,a,sum,sizeof(diction),cmp); if(p) puts(p->eng); else puts("eh"); } return 0; }
- 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(二分)
- Java打包成jar文件,以及将jar文件导出为exe文件方法汇总
- ADT 17 如何解决“出现NoClassDefFoundError“
- eclipse里报错
- Android---Activity生命周期状态
- STL中vector值得注意的两个问题
- poj-2503 Babelfish
- Java Mail 发送邮件
- QT中添加Q_OBJECT出现的问题
- Stack&2分&并查集&Dp&Greddy_081007day2
- kmp算法的php实现,可直接执行
- 花括号({...})在自动资源释放中的作用
- 使用auto_ptr需要注意的事项
- 一次学会,jvm内存不再溢出
- jsp表单验证大全