gnatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
Output
In this problem, you have to output the translation of the history book.
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
Sample Output
hello, i'm from mars.
i like earth!
Hint
Huge input, scanf is recommended.
题意:英文置换,第一个STRAT后输入要置换的英文,以END结束,再以STRAT开始输入测试,以END结束。这题对于我来说难点在于怎么输入和存储测试数据,思路:每一个STRAT用一个while,这样就能分清了。当时我用结构体存储测数据的每一个单词,再查找要替换的单词,,,,结果和之前写过的一些一样,编译器报错,什么寄存器之类的,只能求助于其他巨佬,后来发现了一个只用一个 char a,循环输入,又因为string b是可增加的 b+=a;只要是字母就存储下来,不是就输出 ,scanf单个字符是可以输入空格。完美解决输入测试数据。
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
map<string,string>ma;
int main()
{
string a,b;
char tp;
cin>>a;
while(cin>>a)
{
if(a!="END")
{
cin>>b;
ma[b]=a;//存储置换的单词
}
else
{
break;
}
}
cin>>a;//输入STRAT
getchar();//吸收回车//
a="";//初始化string
while(1)
{
while(1)
{
scanf("%c",&tp);
if(!((tp>='a'&&tp<='z')||(tp>='A'&&tp<='Z')))//是字母就存,不是就跳出
{
break;
}
a+=tp;
}
if(a=="END")//结束标志
{
break;
}
if(ma.find(a)==ma.end())//每次存完一个单词就查找
{
cout<<a;
}
else//没有就置换
{
cout<<ma[a];
}
a="";
printf("%c",tp);//因为最后一次输入必定为非字母,但是这些字符需要输出,所以先输出前面的单词再输出字符
}
}