poj-2503 Babelfish

原创 2012年03月28日 23:24:32
                                                          F - Babelfish
Crawling in process...Crawling failedTime Limit:3000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

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; 
}  

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

POJ2503-Babelfish

POJ 2503——Babelfish

这一题也没什么思路很直接,直接用字典树cunchu

poj2503Babelfish(Trie tree 或者map)

->题目还是戳这里 题目大意:还是给你一个字典,翻译单词。 题目分析:题目蛮简单,字典树练手题。不过STL可以水过。输入有点小刁难,需要小心点,其他的就没什么了。 详情请见代码: #include ...

POJ 2503 Babelfish [map & string]

poj 2503 babel fish

POJ2503 Babelfish Trie树

Problem Address:http://poj.org/problem?id=2503 Trie树(即字典树)。 动态创建。 第一次写字典树,写得很快,连最后的DEBUG都不用,没想到居然一次A...

[POJ2503] Babelfish

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect o...

POJ2503--Babelfish--map映射

Description You have just moved from Waterloo to a big city. The people here speak an incomprehensi...

北大ACM poj2503 Babelfish

Babelfish Description You have just moved from Waterloo to a big city. The people here speak an ...

POJ2503 Babelfish

题目大意:给出英语 --- A国语言 ,然后输入A国语言单词,问在字典内是否有该单词,有就输出该单词英文,无则输出eh; 思路:典型的先保存再查找,有好几种解法,我用得是hash,但是再用链表的时候...

poj 2503 Babelfish

还是字典树的水题一道,输入的方法让我觉得很神奇.........我是菜,输入都搞不好....#include #include #include #include #include #inc...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)