码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 499B.Lecture 解题报告

时间:2014-12-27 00:10:21      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:

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

   

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <map>
 6 using namespace std;
 7 
 8 string value, key;
 9 map <string, string> mss;
10 map<string, string>:: iterator loc;
11 
12 int main()
13 {
14     #ifndef ONLINE_JUDGE
15         freopen("in.txt", "r", stdin);
16     #endif // ONLINE_JUDGE
17 
18     int n, m;
19     while (scanf("%d%d", &n, &m) != EOF)
20     {
21         mss.clear();       // 最后就是为了加这个东西来不及交
22         for (int i = 0; i < m; i++)
23         {
24             cin >> value >> key;
25             mss[value] = key;
26         }
27         for (int i = 0; i < n; i++)
28         {
29             cin >> value;
30             loc = mss.find(value);
31         //    if (loc != mss.end())  // 这个是为了严谨,其实一定能在单词表中找到的
32         //    {
33                 string s1 = mss[value];
34                 string s2 = loc->first;
35                 if (s2.size() <= s1.size())
36                     cout << s2 << " ";
37                 else
38                     cout << s1 << " ";
39        //     }
40         }
41         puts("");
42     }
43     return 0;
44 }

 

codeforces 499B.Lecture 解题报告

标签:

原文地址:http://www.cnblogs.com/windysai/p/4187710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!