您的位置:首页 > 编程语言

编程之美2013全国挑战赛资格赛题题1 传话游戏【简单模拟】

2013-04-06 17:10 309 查看
http://programming2013.cstnet.cn/qualification/problem/1

题目大意:Alice和Bob还有其他几位好朋友在一起玩传话游戏。这个游戏是这样进行的:首先,所有游戏者按顺序站成一排,Alice站第一位,Bob站最后一位。然后,Alice想一句话悄悄告诉第二位游戏者,第二位游戏者又悄悄地告诉第三位,第三位又告诉第四位……以此类推,直到倒数第二位告诉Bob。两位游戏者在传话中,不能让其他人听到,也不能使用肢体动作来解释。最后,Bob把他所听到的话告诉大家,Alice也把她原本所想的话告诉大家。

由于传话过程中可能出现一些偏差,游戏者越多,Bob最后听到的话就与Alice所想的越不同。Bob听到的话往往会变成一些很搞笑的东西,所以大家玩得乐此不疲。经过几轮游戏后,Alice注意到在两人传话中,有些词汇往往会错误地变成其他特定的词汇。Alice已经收集到了这样的一个词汇转化的列表,她想知道她的话传到Bob时会变成什么样子,请你写个程序来帮助她。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
template <class T> void checkmin(T &t,T x) {if(x < t) t = x;}
template <class T> void checkmax(T &t,T x) {if(x > t) t = x;}
template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;}
template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <double,double> PDD;
typedef long long ll;
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)
map <string , string> mp;
int T , cas = 1 , n , m;
string od[111];
int cnt = 0;
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
mp.clear();
cnt = 0;
for(int i=0;i<m;i++) {
string s1 , s2;
cin >> s1 >> s2;
mp[s1] = s2;
}
while(cin >> od[cnt]) {
cnt ++;
char c = getchar();
if(c == '\n') break;
}
for(int i=1;i<n;i++) {
for(int j=0;j<cnt;j++) {
if(mp.count(od[j]))
od[j] = mp[od[j]];
}
}
printf("Case #%d:" , cas ++);
for(int i=0;i<cnt;i++) cout << " " << od[i];
cout << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: