poj 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

其实用cin输入输出也可以map<T,T>dd;以及gets(a)与sscanf(a,"%s",str)配合用法;a为char a[45];
#include<cstdio>
#include<string>
#include<iostream>
#include<map>
using namespace std;

int main()
{    map<string,string>dic;
    char a[11],b[11];
    int i=0;
 char str[21];
    while(gets(str))
    {
      if(str[0]==‘\0‘){break;}
      sscanf(str,"%s %s",a,b);
     dic[b]=a;
    }
    char c[11];
 string qq;
    while(scanf("%s",c)!=EOF)
        {
             string s=c;
           qq=dic[s];
           if(qq.length()==0)cout<<"eh"<<endl;
           else cout<<qq<<endl;

        }

    return 0;
}
时间: 2024-08-04 13:05:27

poj 2503 查字典的相关文章

POJ 2503 Babelfish(字典树)

Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 35009   Accepted: 14979 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

poj 2503 Babelfish(字典树或着STL)

Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 35828   Accepted: 15320 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

POJ 2503 字典树

这题记得以前是我们周赛的题,然后用的是map,也暴过了. 因为这两天要给大一的讲字典树,所以练练几道的代码,以防给大一搞晕了-- #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<queue> #include<set> #include<cmath> #include

字典树模板题 POJ 2503

1 #include <cstdio> 2 #include <cstring> 3 4 char en[11],fr[11]; 5 int st; 6 struct Tire{ 7 int next[26]; 8 char eng[11]; 9 }node[200005]; 10 void insert(char *s,int cur) 11 { 12 if(*s){ 13 if(!node[cur].next[*s-'a']) 14 node[cur].next[*s-'a']

poj 2503:Babelfish(字典树,经典题,字典翻译)

Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 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

codevs2875RY哥查字典

题目链接:http://codevs.cn/problem/2875/ 题目描述 Description RY哥最近新买了一本字典,他十分高兴,因为这上面的单词都十分的和谐,他天天查字典. 输入描述 Input Description 1个整数N,表示字典里面的单词数量. 接下来N行,每行一个字符串,表示一个单词. 然后第N+2行,一个整数M,表示要查的单词数. 接下来M行,每行一个字符串,表示一个要查的单词. 输出描述 Output Description 对于每一个要查的单词,如果在字典里面

RY哥查字典

时间限制: 1 s 空间限制: 16000 KB 题目等级 : 钻石 Diamond 题目描述 Description RY哥最近新买了一本字典,他十分高兴,因为这上面的单词都十分的和谐,他天天查字典. 输入描述 Input Description 1个整数N,表示字典里面的单词数量. 接下来N行,每行一个字符串,表示一个单词. 然后第N+2行,一个整数M,表示要查的单词数. 接下来M行,每行一个字符串,表示一个要查的单词. 输出描述 Output Description 对于每一个要查的单词,

poj 2503 Babelfish (map,trie 树)

链接:poj 2503 题意:输入 语言A及翻译为语言B的词典,之后再输入语言B的单词,判断是否能从词典中找到, 若能找到,将其翻译为语言A,否则输出"eh". 思路:这题肯定得先将词典对应语言存起来,但是如果直接暴力找输入的单词是否出现过,必然会TLE 因为单词都是一对一的关系,可以用map实现 当然,trie树是用空间换时间,对于字符串的查找,在时间上有着相当的优势,因此也可以用trie树 注:sscanf函数,从一个字符串中读进与指定格式相符的数据. map实现:938MS #i

Codevs 2875 RY哥查字典

时间限制: 1 s 空间限制: 16000 KB 题目等级 : 钻石 Diamond 题目描述 Description RY哥最近新买了一本字典,他十分高兴,因为这上面的单词都十分的和谐,他天天查字典. 输入描述 Input Description 1个整数N,表示字典里面的单词数量. 接下来N行,每行一个字符串,表示一个单词. 然后第N+2行,一个整数M,表示要查的单词数. 接下来M行,每行一个字符串,表示一个要查的单词. 输出描述 Output Description 对于每一个要查的单词,