poj-2503 Babelfish
2012-03-28 23:24
357 查看
F -
Babelfish
Crawling in process...Crawling failedTime
Limit:3000MS Memory Limit:65536KB
64bit IO Format:%I64d & %I64u
SubmitStatusPracticePOJ
2503
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
Babelfish
Crawling in process...Crawling failedTime
Limit:3000MS Memory Limit:65536KB
64bit IO Format:%I64d & %I64u
SubmitStatusPracticePOJ
2503
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
先定义一个结构体用来储存字典,然后对字典中的英文进行排序,输入单词,进行查找,若找到,输出相对应的英文,若找不到则就输出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(字典树Trie)
- POJ 2503 - Babelfish(STL)
- poj 2503 Babelfish(广义索引类线性表:快排+二分)
- Poj 2503 Babelfish(map+串的处理)
- POJ 2503 Babelfish(字典树)
- 【POJ】[2503]Babelfish
- POJ2503 Babelfish 二分 TWT Tokyo Olympic 1 COMBO-1
- poj 2503 Babelfish(字典树哈希)
- POJ 2503 Babelfish(map)
- poj 2503 Babelfish
- POJ 2503 Babelfish(Hash)
- poj 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
- poj 2503 Babelfish (查找 map)
- 【POJ】2503 Babelfish
- POJ2503——Babelfish(map映射+string字符串)
- poj 2503 Babelfish
- POJ 2503-Babelfish(STL-map)
- POJ 2503 Babelfish (字典树)