传话游戏

非游戏规则,仅含代码.
编程之美资格赛题一代码
纯C++风格,那什么C风格弱暴了.
大神轻拍.

[code language="cpp"]

#include\<iostream>
#include\<string>
#include\<map>
#include\<vector>
#include\<cstdio>
using namespace std;
map\<string,string> word_change;
vector\<string> sentence;
void change()
{
for(vector\<string>::iterator be=sentence.begin();be!=sentence.end();++be)
{
if(word_change.count(*be)==0)
continue;
if(word_change.count(*be)==1)
*be=word_change[*be];
}
}
int main()
{
int T,N,M;
char en;
cin >> T;
string word,key,value;
for (int i=0 ;i!=T;++i)
{
cin >> N >> M;
for (int j=0;j!=M;++j)
{
cin >> key >> value;
word_change[key]=value;
}
while(cin >> word)
{

sentence.push_back(word);
if((en=getchar())=='\n'|| en==EOF)
break;
}
for(int k=0;k!=N-1;k++)
change();
cout \<\< "Case #" \<\< i+1 \<\< ":";
for(vector\<string>::iterator be=sentence.begin();be!=sentence.end();++be)
cout \<\< " " \<\< *be ;
cout \<\< endl;
word_change.clear();
sentence.clear();
}
return 0;
}

[/code]

Comments