Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay
Sample Output

cat
eh
loops

大致题意:
输入一个字典,字典格式为“英语à外语”的一一映射关系
然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh”

输入时顺便用STL的map标记外语是否出现过,然后再用map建立“外语à英语”的映射,那么输出时先查找“出现”的标记,若有出现过,再输出映射,否则输出“eh”。

题解1:

 # include<iostream>
# include <cstdio>
# include<string>
# include<map>
using namespace std; int main(void)
{
char english[],foreign[]; map<string,string>translate; //记录foreign到engliash的映射 /*Input the dictionary*/ while(true)
{
char t; //temporary if((t=getchar())=='\n') //判定是否输入了空行
break;
else //输入english
{
english[]=t;
int i=;
while(true)
{
t=getchar();
if(t==' ')
{
english[i]='\0';
break;
}
else
english[i++]=t;
}
} cin>>foreign;
getchar(); //吃掉 输入foreign后的 回车符 translate[foreign]=english;
} /*Translate*/ char word[];
while(cin>>word)
{
if(translate.find(word) == translate.end()) //没找到
cout<<"eh"<<endl;
else
cout<<translate[word]<<endl;
} return ;
}

题解2:

 # include<iostream>
# include <cstdio>
# include<string>
# include<map>
using namespace std; int main(void)
{
char english[],foreign[]; map<string,bool>appear; //记录foreign与engliash的配对映射是否出现
map<string,string>translate; //记录foreign到engliash的映射 /*Input the dictionary*/ while(true)
{
char t; //temporary if((t=getchar())=='\n') //判定是否输入了空行
break;
else //输入english
{
english[]=t;
int i=;
while(true)
{
t=getchar();
if(t==' ')
{
english[i]='\0';
break;
}
else
english[i++]=t;
}
} cin>>foreign;
getchar(); //吃掉 输入foreign后的 回车符 appear[foreign]=true;
translate[foreign]=english;
} /*Translate*/ char word[];
while(cin>>word)
{
if(appear[word])
cout<<translate[word]<<endl;
else
cout<<"eh"<<endl;
} return ;
}

POJ 2503 单词映射(map)的更多相关文章

  1. poj 2503 Babelfish (查找 map)

    题目:http://poj.org/problem?id=2503 不知道为什么 poj  的 数据好像不是100000,跟周赛的不一样 2000MS的代码: #include <iostrea ...

  2. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  3. 题解报告:poj 2503 Babelfish(map)

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  4. poj 2503 哈希 Map 字典树

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36967   Accepted: 15749 Descr ...

  5. VIM键盘映射 (Map)~转载

    VIM键盘映射 (Map) 设置键盘映射 使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来.例如使用以下命令,可以通过F5键将单词用花括号括起来: :map <F5> i{e ...

  6. VIM键盘映射 (Map)

    http://www.pythonclub.org/linux/vim/map VIM键盘映射 (Map) 设置键盘映射 使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来.例如使用以下命 ...

  7. 图像映射map

    <map>标签:带有可点击区域的图像映射 定义一个客户端图像映射.图像映射(image-map)指带有可点击区域的一幅图像. 效果图: 点击相应蓝色标签可进入详情页面浏览. 代码: < ...

  8. [51NOD1095] Anigram单词(map)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1095 字典的单词在map中排序和不排序各存1次,查的时候相减. ...

  9. <顶>vim快捷键映射Map使用

    问题描述: 使用vim中的快捷键映射map,可以自定义快捷键 问题解决: (1)vim模式 (2)map前缀 (3)删除映射Map (4)使用示例 (5)查看快捷键映射 命令行---:verbose ...

随机推荐

  1. SQL记录-资源正忙online或nowait

    1.多个tomcat 修改3个端口 2.oracle-00054:资源正忙 被锁住了 建立索引加online参数 1:创建索引时会产生的锁 2:dml 语句会产生的锁 3:索引创建时加上关键字 onl ...

  2. Spring+quartz 实现定时任务job集群配置【原】

    为什么要有集群定时任务? 因为如果多server都触发相同任务,又同时执行,那在99%的场景都是不适合的.比如银行每晚24:00都要汇总营业额.像下面3台server同时进行汇总,最终计算结果可能是真 ...

  3. JS 互相调用iframe页面中js方法、VUE里 iframe 互调方法

    1,父 html 调用子 iframe 内方法: document.getElementById("iframe").contentWindow.func(data1,data2. ...

  4. FASTREPORT COM/ActiveX报表如何保存到C++项目中?

    可以的. VC++ : ... IStream * pStream;CreateStreamOnHGlobal(NULL, true, &pStream);pStream->AddRef ...

  5. EasyUI Combobox 设置默认值

    /** *绑定运营商,设置默认值, 显示CMCC, 传值1 */ $('#operatingId').combobox({ url:'data_url', valueField:'id', textF ...

  6. 后台拿webshell方法(2)

    在这里总结一下后台拿webshell的方法: 备份突破(在博客上有随笔介绍) 一般在后台上传文件类型受到限制,可以利用数据库备份将其上传的格式改为后门执行格式即可: asp更改为jpg     jpg ...

  7. C# 读取Excel和DBF文件

    //获excel中多个sheet中的数据 /// <summary> /// 读取导入Excel文件内容 /// </summary> /// <param name=& ...

  8. javaScript之表格操作<一:新增行>

    DOM表格系列操作 /** * 添加表格行 * @function 本接口可以用于:在表格tbody部分新增任意数量,任意样式的行HTML结构; * @name addTableLines * @au ...

  9. [C++]指针与引用(应用辨析)

    1.指针变量允许将一个整数经强制转换后赋值给指针变量    Eg:      float *fp;      fp = (float *)5000;//意义:将5000作为一个地址赋给指针变量fp 2 ...

  10. yolov3实践(一)

    很多博友看了我的第一篇博客yolo类检测算法解析——yolo v3,对其有了一定的认识和了解,但是并没有贴出代码和运行效果,略显苍白.因此在把篇博客理论的基础上,造就了第一篇实践文章,也就是本文.只要 ...