zoukankan      html  css  js  c++  java
  • 题解报告:poj 2503 Babelfish(map)

    Description

    You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

    Input

    Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

    Output

    Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

    Sample Input

    dog ogday
    cat atcay
    pig igpay
    froot ootfray
    loops oopslay
    
    atcay
    ittenkay
    oopslay
    

    Sample Output

    cat
    eh
    loops
    解题思路:查字典--->map键值对,由于时间限制,要用C语言的输入输出,因此输入时考虑用sscanf函数来格式化读取的字符串,其他常规处理即可。
    int sscanf (const char *str,const char * format,........);
    sscanf函数会将参数str字符串根据参数format字符串来转换并格式化数据,转换后的结果存于对应的参数内。返回值:如果成功,该函数返回成功匹配和赋值的个数。如果到达文件末尾或发生读错误,则返回EOF。

    AC代码(2157ms):
     1 #include<iostream>
     2 #include<map>
     3 #include<string.h>
     4 #include<cstdio>
     5 using namespace std;
     6 const int maxn=30;
     7 char str[maxn],obj[maxn],ans[maxn];
     8 map<string,string> mp;
     9 int main(){
    10     while(gets(str)&&strlen(str)){
    11         sscanf(str,"%s%s",ans,obj);//格式字符串
    12         mp[obj]=ans;//映射(字典)
    13     }
    14     while(gets(str)){
    15         if(mp.find(str)!=mp.end())printf("%s
    ",mp[str].c_str());
    16         else printf("eh
    ");
    17     }
    18     return 0;
    19 }
  • 相关阅读:
    ASP.NET页面打印技术的总结
    js传递中文参数的url到asp(jscript)解释得到的中文参数为乱码的解决方法
    header的用法(PHP)
    oracle 11g road(/dev/shm需注意)
    mysql 主从同步 Error 'Out of range value for column的问题
    linux shell 过滤特殊字符开始的行
    Oracle穿越incarnation恢复数据
    多普达A6388刷机2.3
    【忽悠普通人用】隐藏文件夹的方法
    电脑同时使用双网卡实现方法
  • 原文地址:https://www.cnblogs.com/acgoto/p/9508906.html
Copyright © 2011-2022 走看看