zoukankan      html  css  js  c++  java
  • 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 提交....人生之痛 = =

       

     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];     // key
    34                 string s2 = loc->first;     // value
    35                 if (s2.size() <= s1.size())   // value 的长度 <= key 的长度 (即word1 <= word2) 
    36                     cout << s2 << " ";        // 输出 word1 的单词
    37                 else
    38                     cout << s1 << " ";
    39        //     }
    40         }
    41         puts("");
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    [OpenGL ES 071]光照原理
    [OpenGL ES 03]3D变换:模型,视图,投影与Viewport
    [日志]当今最流行的网络生僻字,很火
    [日志]关于茶的基础知识
    [健康]快速除牙痛的八个小验方
    [日志]我们生活中的潜规则
    [日志]做事要方,做人要圆
    [日志]家居装修花钱看你怎么省
    [日志]非常宝贵的工作经验
    [日志]你用的着的一些家装尺寸数据
  • 原文地址:https://www.cnblogs.com/windysai/p/4187710.html
Copyright © 2011-2022 走看看