hdu 1075 What Are You Talking About
来源:互联网 发布:汉王霾表测甲醛 知乎 编辑:程序博客网 时间:2024/06/03 02:16
以前这道题没过,需要用到字典树,当时不会,最近新学了unordered_map(hash map),结果hdu平台说找不到这个库,没办法,只好用map了,直接过了
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075
#include <iostream>#include <map>#include <string>#include <cctype>using namespace std;//输入数据并生成字典dicvoid inputDictionary(map<string, string> &dic){string word, mars;while(cin >> word){if(word.compare("END") == 0)return;cin >> mars;map<string, string>::iterator a = dic.find(mars);if(a == dic.end())dic.insert(pair<string, string>(mars, word));}}//获取单词string getWord(const string &line, string::iterator &it){string r = "";if(it == line.end())return r;string::iterator t = it;for( ; t!= line.end() && !isalpha(*t); t++);if(t != it){r.assign(it, t);it = t;return r;}for( ; t != line.end() && isalpha(*t); t++);r.assign(it, t);it = t;return r;}//将一行line翻译void translate(map<string, string> &dic, string &line){string::iterator t = line.begin();while(true){string word = getWord(line, t);if(word.empty())break;if(!isalpha(word[0]))cout << word;else{map<string, string>::iterator b = dic.find(word);if(b != dic.end())cout << (*b).second;elsecout << word;}}}int main(){//freopen("t.txt", "r", stdin);string s;map<string, string> dic;getline(cin, s);inputDictionary(dic);getchar();getline(cin, s);while(true){getline(cin, s);if(s.compare("END") == 0)break;translate(dic, s);cout << endl;}//system("pause");return 0;}
0 0
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU-1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- HDU-1075-What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- Hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu-1075-What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- 简单的发邮件
- 自己动手写CSDN博客提取器源码分析之二:处理网页保存为doc文件
- C++11中once_flag,call_once实现分析
- cout 格式化输出
- C++Primer学习笔记《三》
- hdu 1075 What Are You Talking About
- Android SDK更新 Connection to http://dl-ssl.google.com refused 解决方法
- java执行js代码
- java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 1解决办法
- PAT 1006. Sign In and Sign Out
- 错误记录--更改tomcat端口号方法,Several ports (8005, 8080, 8009)
- vector和list区别
- Spark资讯汇总(微信公共号:Spark大数据)
- 卸载oracle11g