蒜厂秘籍(map)
来源:互联网 发布:retrofit post json 编辑:程序博客网 时间:2024/04/30 14:44
题目思路:用STL中的map
学到的东西 string的迭代器是auto ,一整行的输入getline(cin,string)
代码:
#include <bits/stdc++.h>using namespace std;int main() { string start1;cin>>start1; string x,y; map<string, string> m; while (true) { cin>>x; if (x=="END") { break; } cin>>y; m[y]=x; } string start2; getline(cin,start2);//吸收\n string sentences=""; while (true) { string line;getline(cin,line); if (line=="START") continue; if (line=="END") break; string words=""; for (auto i =line.begin();i!=line.end();i++) { if (isalpha(*i)) words+=*i; else { if (words!="") { if(m.count(words)) sentences+=m[words]; else sentences+=words; } sentences+=*i;//句子加上非字母的 words.clear();//清空words } } if (words!="") {//处理最后以单词结尾的 if(m.count(words)) sentences+=m[words]; else sentences+=words; } sentences+='\n'; } cout<<sentences; }
阅读全文
0 0
- 蒜厂秘籍(map)
- 计蒜客 蒜厂秘籍
- QQ秘籍(二)
- GOOGLE搜索秘籍 (转)
- Struts 秘籍(CookBook)索引
- iphone开发秘籍(一)
- ConstraintLayout 终极秘籍(上)
- web 打印的终极秘籍(整理)
- web 打印的终极秘籍(整理)
- 独家追女孩秘籍!(一)
- 独家追女孩秘籍!(二)
- 独家追女孩秘籍!(三)
- 独家追女孩秘籍!(四)
- 独家追女孩秘籍!(五)
- 独家追女孩秘籍!(六)
- 泡妞秘籍大全(技术贴)
- Android开发秘籍学习笔记(一)
- Android开发秘籍学习笔记(二)
- 3DSlicer7:FAQ-1
- Verilog运算符优先级
- Qtmsvc2010+Opencv2.4.9配置
- Python相关链接
- Class JavaLaunchHelper is implemented in both … libinstrument.dylib. One of the two will be used. Wh
- 蒜厂秘籍(map)
- LCD1620
- 分布式ZooKeeper-3.4.10集群安装
- Linux普通用户jdk配置
- 禁止遮罩的滑动事件
- PCIe学习笔记(34)--- DLL (1)
- 2008下搭建easypanel(康乐)虚拟主机控制面板
- Freemarker自定义指令
- 基于Dragonboard 410c的音乐储钱罐(三)