codeforces 499B.Lecture 解题报告
2014-12-26 23:41
225 查看
题目链接:http://codeforces.com/problemset/problem/499/B
题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 professor's lecture 的 n 个单词。问记下来的笔记是什么。对于professor's lecture 的某个单词,如果在单词表中找到,word1, word2 都有可能。如果 word1 的长度 <= word2 的长度,就输出word1,否则word2
考了map<string, string>的用法,这个我参考了之前在 zoj 做的一条题1109 Language of FatMouse,依样画葫芦写出来的,只是最后要比较 size()而不是直接映射。。。无谓的百度花了很长时间,关键没有找到所需的= = ,还有就是那些 key 和 value 的位置, 最悲剧的是,就差那么一点点调试,来不及在 virtual 提交....人生之痛 = =
题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 professor's lecture 的 n 个单词。问记下来的笔记是什么。对于professor's lecture 的某个单词,如果在单词表中找到,word1, word2 都有可能。如果 word1 的长度 <= word2 的长度,就输出word1,否则word2
考了map<string, string>的用法,这个我参考了之前在 zoj 做的一条题1109 Language of FatMouse,依样画葫芦写出来的,只是最后要比较 size()而不是直接映射。。。无谓的百度花了很长时间,关键没有找到所需的= = ,还有就是那些 key 和 value 的位置, 最悲剧的是,就差那么一点点调试,来不及在 virtual 提交....人生之痛 = =
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> using namespace std; string value, key; map <string, string> mss; map<string, string>:: iterator loc; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // ONLINE_JUDGE int n, m; while (scanf("%d%d", &n, &m) != EOF) { mss.clear(); // 最后就是为了加这个东西来不及交 for (int i = 0; i < m; i++) { cin >> value >> key; mss[value] = key; } for (int i = 0; i < n; i++) { cin >> value; loc = mss.find(value); // if (loc != mss.end()) // 这个是为了严谨,其实一定能在单词表中找到的 // { string s1 = mss[value]; // key string s2 = loc->first; // value if (s2.size() <= s1.size()) // value 的长度 <= key 的长度 (即word1 <= word2) cout << s2 << " "; // 输出 word1 的单词 else cout << s1 << " "; // } } puts(""); } return 0; }
相关文章推荐
- 解题报告 生物
- HDU:2097,2098,1021,2035 解题报告
- 解题报告 之 POJ1021 Fibonacci Again
- 解题报告 Paid Roads
- 杭电OJ题 1280 前m大的数 解题报告
- Swap Nodes in Pairs ——解题报告
- [pa2015]Fibonacci 解题报告
- 中中救援队 解题报告
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps 解题报告
- PKU Campus 2015解题报告
- 【九度OJ】题目1069:查找学生信息 解题报告
- 【最短路】解题报告
- 四月月赛解题报告
- Codeforces Round #244 (Div. 2)(解题报告)
- 区间第K大数——划分树(POJ2104解题报告)
- 山东省第四届ACM Mountain Subsequences 解题报告
- 【任务分配】解题报告
- POJ 1146 解题报告
- 2014-05-08360 网络攻防 hackgame 解题报告(通关)
- 二项堆运用——hdu1512解题报告