Decoding Baby Boos

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83008#problem/A

Description

Osantu has been tagged as the best Bangladeshi contestant of present time by many and now he is mostly busy with the sweetest problem of his life — a baby boy. But Osantu often struggles to decode the sound that the baby makes throughout the year and so he asks for your help. He has converted the sound that the baby makes into a huge string. He thinks that sound made by the baby is often hard to understand because he replaces one character with another character. So in his diary he has prepared a list of replacement rules. Your job is to reverse these replacements and find the actual text that the baby wanted to say although in many cases the rules are not reversible.

Input

First line of the input file contains a positive integer T (T ≤ 6) which denotes how many test cases are there in the input file. The description of each test case is given below:

First line of each test case contains a non-empty string S (containing only uppercase characters and underscore). The length of this string can be up to 1000000. Next line contains a positive integer R (R ≤ 10000), which denotes how many character replacement sequences follow. Each of the next R lines contains two characters ai and bi (both ai and bi are uppercase letters and separated by a single space) which denotes that while pronouncing the baby replaces character ai with character bi . As this replacement list is prepared by Osantu (who has short term memory) so the list can contain the same replacement rules twice, there can be cyclic rules like ‘A’ is replaced with ‘B’, ‘B’ is replaced with ‘C’ and ‘C’ is replaced with ‘A’ and also there can be contradicting rules like ‘A’ is replaced with ‘B’ and ‘A’ is replaced with ‘C’ etc. So what you simply need to do is apply the reverse of those rules in the order they appear in the input although it may not seem logical.

Output

For each set of input produce one line of output. This line contains the string that is found by applying all the R replacement rules.
Illustration of the 2nd sample input:
First replacement rule says the baby replaces ‘A’ with ‘B’. So to reverse that rule all ‘B’ s are replaced with ‘A’. So the string becomes “AAAACCY”. The 2nd rule says ‘B’ is replaced with ‘C’ and so to reverse this rule we replace all ‘C’s with ‘B’ and so the string becomes “AAAABBY”. The 3rd rule says that ‘C’ is replace with ‘A’ and so to reverse that we now replace all ‘A’s with ‘C’ and so the string finally becomes “CCCCBBY”.

Sample Input

2
AVVU_TUMI_COLING_PARO_NAY
3
B V
D L
H Y
AABBCCY
3
A B
B C
C A

Sample Output

ABBU_TUMI_CODING_PARO_NAH
CCCCBBY

HINT

题意

给你一个字符串,以及一些替换,要求你把这些单词换成另外的单词

问你最后这个字符串是什么样子

题解:

直接暴力换就好了~

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//**************************************************************************************int flag[30];
int main()
{int t=read();for(int cas=1;cas<=t;cas++){for(int i=0;i<30;i++)flag[i]=i;string s;cin>>s;int q=read();while(q--){char a,b;cin>>a>>b;for(int i=0;i<30;i++){if(flag[i]==b-'A')flag[i]=a-'A';}}for(int i=0;i<s.size();i++){if(s[i]>'Z'||s[i]<'A')cout<<s[i];elseprintf("%c",flag[s[i]-'A']+'A');}printf("\n");}
}

UVA 12897 Decoding Baby Boos 暴力相关推荐

  1. UVA12897 - Decoding Baby Boos

    没必要每次都真的修改一遍字母值,用一个标记表示字母最后的值,最后一遍的时候再进行修改 #include<cstdio> #include<cstring>const int m ...

  2. 【字符串处理】UVALive - 6917 Decoding Baby Boos

    Problem Description 给你T组数据,每组数据先给你一个串,只包含大写字母或者下划线.给你m组操作,每组操作有u, v两个大写字母,就是将串里面的所有字母v变成字母u 思路:把B变成A ...

  3. UVA 10976 Fractions Again?!【暴力枚举/注意推导下/分子分母分开保存】

    [题意]:给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对. [分析]:枚举所有在区间[k+1, 2k]上的 y 即可,当 1/k - 1/y 的结果分子为1即为一组解. [ ...

  4. General Sultan UVA - 11604(建图暴力)

    给出n个字符串,询问是否存在一个字符串(可以是给出的几个中的 也可以是组合成的),使得用字符串(随便你用多少个)来拼凑这个串,能够至少有两种拼法 解析: 把每一个字符串的每一个位置的字符看作结点,进行 ...

  5. UVA 725 Divisions 除法(暴力,0 ms)

    本题较为简单,将不会编写算法分析说明与代码编写指导. AC 代码(0 ms): #include<cstdio> #include<cstdlib> #include<c ...

  6. pca算法python代码_三种方法实现PCA算法(Python)

    主成分分析,即Principal Component Analysis(PCA),是多元统计中的重要内容,也广泛应用于机器学习和其它领域.它的主要作用是对高维数据进行降维.PCA把原先的n个特征用数目 ...

  7. 暴力枚举 UVA 725 Division

    题目传送门 1 /* 2 暴力:对于每一个数都判断,是否数字全都使用过一遍 3 */ 4 #include <cstdio> 5 #include <iostream> 6 # ...

  8. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  9. UVA - 213 Message Decoding

    Message Decoding UVA - 213 题目传送门 emmmm,此题按照紫书上的思路来即可,要么太复杂 AC代码: #include <cstdio> #include &l ...

最新文章

  1. 【OpenCV 】Sobel 导数/Laplace 算子/Canny 边缘检测
  2. 从信息时代到智力时代的药物发现
  3. 开源中国 Maven 库
  4. 企业安全挑战 内网安全技术十大策略
  5. 计算机网络复习_第一章
  6. Servlet/Tomcat/ Spring 之间的关系
  7. Java实现栈(顺序栈,链栈)
  8. linux版本的redis bin,Linux下安装Redis4.0版本(简便方法)
  9. 用根因定位法,让运维效率再高一点!
  10. sql STUFF 分组
  11. My Ruby Blog
  12. 仅用 480 块 GPU 跑出万亿参数,中文最大规模多模态预训练模型发布
  13. C++定时器和时间轮
  14. easyweb前端框架的资料
  15. rms 公式 有效值_有效值、真有效值、基波有效值、全有效值概念辨析
  16. 天地劫一直说服务器在维护,天地劫手游网络连接错误怎么办 天地劫幽城再临网络异常解决方法...
  17. metro样式开机启动菜单_如何在Windows 8中获取Metro风格的开始菜单和开始按钮
  18. 华为5G手机+鸿蒙系统,还能这么玩儿?
  19. 【pandas】df.str.contains包含多个值写法
  20. 微信支付不能调起微信支付页面

热门文章

  1. 短信验证码60秒倒计时
  2. 计算机语言算法大全,经典算法大全
  3. AppScan使用手册
  4. 商标名称注册查询有那些注意!
  5. Vue+Ant Design of Vue上传文件,并限制上传文件数及限制其类型
  6. SpringBoot报错:Error starting ApplicationContext. To display the conditions report re-run your applica
  7. 那些年我们一起追过的技术和开源软件
  8. Python 二分查找(涉及递归思想)
  9. Bootstrap多个手风琴折叠展开效果
  10. mysql锁定某一行_MySQL高级学习之行锁