hdu 1075 map+string
来源:互联网 发布:合肥淘宝合作快递 编辑:程序博客网 时间:2024/05/19 05:40
Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn’t know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string “START”, this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian’s language. A line with a single string “END” indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string “START”, this string should be ignored, then an article written in Martian’s language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can’t find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(’ ‘), tab(‘\t’), enter(‘\n’) and all the punctuation should not be translated. A line with a single string “END” indicates the end of the book part, and that’s also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
Output
In this problem, you have to output the translation of the history book.
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i’m fiwo riwosf.
i fiiwj fnnvk!
END
Sample Output
hello, i’m from mars.
i like earth!
题解:
简单字符串map处理。注意最后一位没有标点字符的情况。
一次AC
代码:
#include <bits/stdc++.h>using namespace std;map<string,string> m;int main(){ string str,org,tmp; cin>>str; while(cin>>org>>tmp) { if(org=="END") break; else m[tmp]=org; } getchar(); while(getline(cin,str)) { if(str=="END") break; tmp=""; int siz = str.size(); for(int i=0;i<siz;i++) { if(isalpha(str[i])) tmp+=str[i]; else { if(tmp!=""){ if(m.count(tmp)) cout<<m[tmp]; else cout<<tmp; } cout<<str[i]; tmp=""; } } if(tmp!="") { if(m.count(tmp)) cout<<m[tmp]; else cout<<tmp; } printf("\n"); } return 0;}
- hdu 1075 map+string
- hdu 1075 What Are You Talking About< map<string,string> >
- hdu 4909 String(map)
- HDU-1113-STL的map<string,string>
- hdu 1251 统计难题< map<string,int> >
- hdu 1381 Crazy Search (map+string||hash)
- hdu 4909 String (map + 状压)
- hdu 4821 String(字符串hash+map)
- hdu 1075 map
- HDU 1075 map解法
- hdu 1247 字典树以及map+string 2种做法
- HDU 4821 String 字符串hash map的妙用
- HDU 1113 Word Amalgamation (map 容器 + string容器)
- 【map容器+string】hdu 5427 A problem of sorting
- HDU 1251:统计难题【字典树 & string+map】
- 【HDU】1251 - 统计难题(字典树 || STL - map & string)
- 【HDU-oj】-6015-Skip the Class(map string vector)
- Map.Entry<String,String>
- presentViewController多级跳转返回
- 百度网盘下载慢,解决方法
- windows性能监控
- 安卓开发帧动画使用
- PAT-AL 1022. Digital Library
- hdu 1075 map+string
- 论文阅读理解
- [转]ubuntu 14.04 下利用apt-get方式安装opencv
- 判断手机号密码格式特殊字符正则
- 前端静态资源库
- Jsoncpp配置
- 修改TabLayout下划线的宽度和文字和线的距离
- if条件判断用户合法性
- 测试和调试 容器化Node应用