国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

poj Babelfish(二分||map)

2019-11-08 02:23:07
字體:
來源:轉載
供稿:網友
 Babelfish

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.方法一:map記錄并查找代碼:
#include<stdio.h>#include<iostream>#include<map>using namespace std;int main(){    map<string,string>translate;    char a[22],b[11],c[11];    while(gets(a)&&a[0]!='/0')    {        sscanf(a,"%s %s",b,c);        translate[c]=b;    }    while(gets(a))    {        if(translate.find(a)!=translate.end())            cout<<translate[a]<<endl;        else            cout<<"eh"<<endl;    }    return 0;}方法二:二分查找代碼:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{    char s1[15],s2[15];}a[100010];int len;bool cmp(node a,node b){    return strcmp(a.s2,b.s2)<0;}int main(){    char s[22];    len=0;    while(gets(s)&&s[0]!='/0')    {        sscanf(s,"%s %s",a[len].s1,a[len].s2);        len++;    }    sort(a,a+len,cmp);    while(gets(s))    {        int x=0,y=len-1,flag=1;        while(x<=y)        {            int mid=(x+y)>>1;            if(!strcmp(s,a[mid].s2))            {                printf("%s/n",a[mid].s1);                flag=0;                break;            }            else if(strcmp(s,a[mid].s2)<0)                y=mid-1;            else                x=mid+1;        }        if(flag)            printf("eh/n");    }    return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 含山县| 盐池县| 兴国县| 宜川县| 黄骅市| 平远县| 富民县| 临汾市| 汽车| 清镇市| 卢龙县| 湖口县| 韩城市| 蒲城县| 营山县| 巴南区| 桐梓县| 江都市| 康平县| 安新县| 绥阳县| 徐州市| 依兰县| 金沙县| 通州市| 永顺县| 永平县| 新平| 潜山县| 明星| 日土县| 聂拉木县| 章丘市| 河津市| 来安县| 嘉禾县| 永寿县| 凤庆县| 洪雅县| 招远市| 江都市|