ACM程序设计题目 Problem B-2

来源:互联网 发布:nemocup软件 编辑:程序博客网 时间:2024/04/29 12:40

//意思就是翻译语句,在输入中给出每个单词对应的单词,输入时输入一个空行结束输入,输入单词,然后输出对应的单词。
//使用map映射,存入对应的单词,主要是碰到空行结束输入,这个地方我是想用getchar处理的,但是使用cin时是错误的答案,然后根据答案把输入改了
sscanf(s.c_str(),"%s %s",s1,s2); 
//然后这样即通过了,之前用的cin>>s1>>s2;就是错误的答案。
#include <bits/stdc++.h>using namespace std;int main(){ string s;  char s1[100],s2[100];  int x,y;  map<string,string>m;  map<string,string>::iterator p;  while(getline(cin,s))  {  if(s=="")break;  else  { sscanf(s.c_str(),"%s %s",s1,s2);  m[s2]=s1;  }  }  while(cin>>s)  {  p=m.find(s);  if(p!=m.end())  cout<<m[s]<<endl;  else  cout<<"eh"<<endl;  }  return 0; }
//新get了查找的使用方式

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 ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Output for Sample Input

catehloops
#include <bits/stdc++.h>using namespace std;int main(){ string s;  char s1[100],s2[100];  int x,y;  map<string,string>m;  map<string,string>::iterator p;  while(getline(cin,s))  {  if(s=="")break;  else  { sscanf(s.c_str(),"%s %s",s1,s2);  m[s2]=s1;  }  }  while(cin>>s)  {  p=m.find(s);  if(p!=m.end())  cout<<m[s]<<endl;  else  cout<<"eh"<<endl;  }  return 0; }
sscanf(s.c_str(),"%s %s",s1,s2); 
0 0
原创粉丝点击