codeforces 499B.Lecture 解题报告

时间:2023-03-08 22:19:57
codeforces  499B.Lecture  解题报告

题目链接: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 提交....人生之痛 = =

 #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 = ; i < m; i++)
{
cin >> value >> key;
mss[value] = key;
}
for (int i = ; 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 ;
}