POJ 2503 单词映射(map)
2015-05-12 17:13
218 查看
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[11],foreign[11]; 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[0]=t; int i=1; 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[11]; while(cin>>word) { if(appear[word]) cout<<translate[word]<<endl; else cout<<"eh"<<endl; } return 0; }View Code
相关文章推荐
- poj_2503(map映射)
- poj_2503(map映射)
- POJ 2153 Rank List (map映射)
- poj 2503 Babelfish(字典树或map或哈希或排序二分)
- poj 2503 Babelfish (map)
- POJ 2503 Babelfish 字典树经典题 三种方法 (map,排序+二分,字典树)
- STL之map——解决POJ 2503
- POJ 2503 Babelfish(hash + map)
- POJ2503 Babelfish map做法
- poj 2503 Babelfish (map)
- POJ(2503)(两种方法,二分,Map)
- POJ_2503_Babelfish_(Trie/map)
- poj_2503_Babelfish(字典树&&map)
- POJ 2503 //map
- 【留坑】 POJ2503 注意输入输出&&几种数据结构的复习、比较(线性表建立的字典 || 树建立的字典_即Trie || hash || map)
- poj 2503 map应用 与 C 输入问题
- POJ 2503 Babelfish(人造字典map)
- poj 2503 (map)
- POJ 2503-Babelfish(STL-map)
- poj 2503 Babelfish (map,trie 树)