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);
- ACM程序设计题目 Problem B-2
- 《ACM程序设计》书中题目--problem b
- 《ACM程序设计》书中题目B-2
- 《ACM程序设计》书中题目--problem j
- 《ACM程序设计》书中题目--problem o
- 《ACM程序设计》书中题目--problem u
- ACM程序设计题目 Problem. J-10
- ACM程序设计题目 Problem. T-20
- 《ACM程序设计》书中题目--problem l
- ACM程序设计》书中题目--problem t
- 《ACM程序设计》书中题目--problem k
- ACM程序设计题目 Problem Z-26
- ACM程序设计题目 Problem K-11
- ACM程序设计题目 Problem O-15
- ACM程序设计题目 Problem U-21
- 《ACM程序设计》书中题目--problem m
- 《ACM程序设计》书中题目--problem n
- ACM程序设计题目 Problem X-24
- javascript操作表单
- 防火墙 的配置规则 学习随笔
- OpenGL版本与OpenGL扩展机制
- CouchBase C 客户端接口调用实例
- Mybatis学习中遇到的异常(3)
- ACM程序设计题目 Problem B-2
- P1223排队接水
- javaWEB总结(35):其他的servlet监听器
- 二进制中1的个数
- ubuntu下Matlab_Linux添加SVM toolbox
- GYM 101147 G.The Galactic Olympics(dp)
- 使用字节流复制一个文件夹
- Linux块设备驱动(一) _驱动模型
- Android Studio 编译错误整理