• POJ 2503 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 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.
     这题没写出来,网上有许多解法,字典树,哈希,map,
    我觉得map很好写的,自己stl太水,我在网上看了两篇不错的map代码,虽然第二份超时了,但我觉得
    我学到了很多,string 里的一些函数,第一份也让自己知道sscanf 的一些用法
     1 #include <iostream>
     2 #include <map>
     3 #include <cstring>
     4 #include <string>
     5 #include <cstdio>
     6 using namespace std;
     7 char s[30], s1[15], s2[15];
     8 string s3, tmp;
     9 map <string, string> mp;
    10 map <string, string> :: iterator it;
    11 int main()
    12 {
    13     while(gets(s)&&strlen(s))
    14     {
    15         sscanf(s, "%s %s", s1, s2);
    16         mp[s2] = s1;
    17     }
    18     while(cin >> s3)
    19     {
    20         it = mp.find(s3);
    21         if(it == mp.end())
    22             cout <<"eh"<< endl;
    23         else
    24             cout <<it ->second << endl;
    25     }
    26 }
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<map>
     4 #include<cstring>
     5 using namespace std;
     6 int main()
     7 {
     8     string s;
     9     map<string,string>Q;
    10     while(getline(cin,s)&&s.length()!=0)
    11     {
    12         int blank=s.find(' ');//урЁЖ©у╦Я╣дн╩жц
    13         string x=s.substr(0,blank);
    14         string y=s.substr(blank+1);
    15         Q[y]=x;
    16     }
    17     string z;
    18     while(cin>>z)
    19     {
    20         if((Q[z].length())==0)
    21             cout<<"eh"<<endl;
    22         else
    23             cout<<Q[z]<<endl;
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    初识python
    文件操作
    初识python
    pycharm IDE
    初识python
    初识Python
    python之网络编程-多线程
    python之并发编程-进程之间的通信
    python之并发编程-多进程
    python之并发编程-操作系统
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5692933.html
Copyright © 2020-2023  润新知