B-2

    xiaoxiao2021-03-25  58

    Description We all know that FatMouse doesn't speak English. But now he has to be prepared since our nation will join WTO soon. Thanks to Turing we have computers to help him. Input Specification Input consists of up to 100,005 dictionary entries, followed by a blank line, followed by a message of up to 100,005 words. Each dictionary entry is a line containing an English word, followed by a space and a FatMouse word. No FatMouse word appears more than once in the dictionary. The message is a sequence of words in the language of FatMouse, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters. Output Specification Output is the message translated to English, one word per line. FatMouse 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 Output for Sample Input cat eh

    loops

    题意描述:

    有一串字符串,空格前面为单词,空格后面为Fatemouse语言,要求输入Fatemouse时,可以输出对应的单词,如若无对应单词,输出eh.

    解题思路:

    定义两个字符串,分别将单词和语言存入,并且将他们放入map中。

    解题细节:

    注意映照容器的使用。

    代码:

    #include <bits/stdc++.h> using namespace std; map<string,string>v; int main() { string str1,str2,str; int i,j; while(getline(cin,str)) { str1.clear(); str2.clear(); if(str[0]=='\0')break; for(i=0;i<str.length();i++) { if(str[i]==' ') break; str1+=(str[i]); } for(j=i+1;j<str.length();j++) str2+=(str[j]); v[str2]=str1; } while(cin>>str2) { if(v[str2]!="") cout<<v[str2]<<endl; else cout<<"eh"<<endl; } return 0; } 心得:

    作用STL解决问题,提供了程序的效率,减少了程序运行的时间。

    转载请注明原文地址: https://ju.6miu.com/read-38265.html

    最新回复(0)