码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2503 Babelfish qsort+bserach

时间:2015-08-19 20:41:19      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:poj   iostream   数据结构   编程   

 

Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 36951   Accepted: 15743

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

Hint

Huge input and output,scanf and printf are recommended.

Source

acCODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
using namespace std;
struct Node{
    char word[20];
    char map[20];
}me[200000];
int cmp(const void *a,const void *b){
    return strcmp(((Node*)a)->map,((Node*)b)->map);
};
int bcmp(const void *a,const void *b){
    return strcmp(((char*)a),((Node*)b)->map);
};
int main(){
    char s[60];
    int n=0;
    Node *pos;
    while(gets(s)&&s[0]!='\0'){
        sscanf(s,"%s %s",me[n].word,me[n].map);
        n++;
    }
    qsort(me,n,sizeof(me[0]),cmp);
    while(gets(s)&&s[0]!='\0'){
        pos=(Node*)bsearch(s,me,n,sizeof(me[0]),bcmp);
        if(pos)printf("%s\n",pos->word);
        else printf("eh\n");
    }
    return 0;
}


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

POJ 2503 Babelfish qsort+bserach

标签:poj   iostream   数据结构   编程   

原文地址:http://blog.csdn.net/zp___waj/article/details/47783985

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!