【题目描述】神族文字(dictionary.cpp/c/pas)
输入文件 | 输出文件 |
---|---|
dictionary.in | dictionary.out |
楚继光发现图书馆里收藏有许多上古时代的魔法书,这些上古时代的魔法书使用一种传说中的“神族文字”来书写,幸运的是,楚继光手边恰巧有一本词典可以帮助他。
【输入格式】
输入的词典内容最多包含有100000个词条,每一个词条包含一个英文单词,其次是一个空格和一个对应的“神族文字”。没有一个“神族文字”在词典中出现一次以上。词典词条全部输入完毕后是一个空行,之后是需要翻译的“神族文字”,每一个词一行,每个单词是一个最多为10个小写字母的字符串。
【输出格式】
输出翻译好的英文,每行一个字。若词典中查找不到,输出“eh”。
【输入样例】
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
【输出样例】
cat
eh
loops
STL标准代码
//神族文字-STL版
#include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<map>
using namespace std;
int main()
{
freopen("dictionary.in","r",stdin);
freopen("dictionary.out","w",stdout);
char english[11],foreign[11];
map<string,string>translate;//记录foreign到engliash的映射
while(true)//输入字典
{
char t; //临时变量
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后的 回车符
translate[foreign]=english;
}
char word[11];
while(cin>>word)//开始翻译
{
if(translate[word]!="")
cout<<translate[word]<<endl;
else
cout<<"eh"<<endl;
}
return 0;
}