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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int flag[];
int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
for(int i=;i<;i++)
flag[i]=i;
string s;
cin>>s;
int q=read();
while(q--)
{
char a,b;
cin>>a>>b;
for(int i=;i<;i++)
{
if(flag[i]==b-'A')
flag[i]=a-'A';
}
}
for(int i=;i<s.size();i++)
{
if(s[i]>'Z'||s[i]<'A')
cout<<s[i];
else
printf("%c",flag[s[i]-'A']+'A');
}
printf("\n");
}
}

UVA 12897 Decoding Baby Boos 暴力的更多相关文章

  1. UVA12897 - Decoding Baby Boos

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

  2. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  3. UVA.10986 Fractions Again (经典暴力)

    UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...

  4. UVA 270 Lining Up 共线点 暴力

    题意:给出几个点的位置,问一条直线最多能连过几个点. 只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可. 我这样做过于暴力,2.7s让人心惊肉跳...应该还能继续剪枝的,同一直线找过之后 ...

  5. uva 10825 - Anagram and Multiplication(暴力)

    题目链接:uva 10825 - Anagram and Multiplication 题目大意:给出m和n,要求找一个m位的n进制数,要求说该数乘以2~m中的随意一个数的结果是原先数各个位上数值的一 ...

  6. UVa 11210 Chinese Mahjong (暴力,递归寻找)

    题意:这个题意.有点麻烦,就是说给定13张牌,让你求能“听”的牌.(具体的见原题) 原题链接: https://uva.onlinejudge.org/index.php?option=com_onl ...

  7. UVa 11059 最大乘积 java 暴力破解

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  8. UVa 817 According to Bartjens (暴力,DFS)

    题意:给出一个数字组成的字符串,然后在字符串内添加三种运算符号 * + - ,要求输出所有添加运算符并运算后结果等于2000的式子. 所有数字不能有前导0, 且式子必须是合法的. 析:这个题很明显的暴 ...

  9. UVA 10976 分数拆分【暴力】

    题目链接:https://vjudge.net/contest/210334#problem/C 题目大意: It is easy to see that for every fraction in ...

随机推荐

  1. UML系列图------用例图介绍

    UML-Unified Model Language 统一建模语言,又称标准建模语言.是用来对软件密集系统进行可视化建模的一种语言. 在UML系统开发中有三个主要的模型: 功能模型: 从用户的角度展示 ...

  2. SoapUI中Groovy的实用方法

    1.依照上次结果判断下步是否执行: import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus myTestStep ...

  3. eclipse 文本编辑器

    Eclipse文本编辑器拥有编辑器的标准功能,包括数目不限的Undo(Ctrl+Z)和Redo(Ctrl+Y)操作.使用快捷键Ctrl+F后,会出现Find/Replace对话框,快捷键Ctrl+K或 ...

  4. ISO-8859-1

    ISO-8859-1编码是单字节编码,向下兼容ASCII,其编码范围是0x00-0xFF,0x00-0x7F之间完全和ASCII一致,0x80-0x9F之间是控制字符,0xA0-0xFF之间是文字符号 ...

  5. BPDU与PortFast

    启用了BPDU Guard特性的端口在收到BPDU的时候会使端口进入err-disable状态,从而避免桥接环路.一般BPDU Guard是和PortFast结合使用,在端口上启用了PortFast之 ...

  6. python内建函数sorted方法概述

    python中,具体到对list进行排序的方法有俩,一个是list自带的sort方法,这个是直接对list进行操作,只有list才包含的方法:另外一个是内建函数sorted方法,可以对所有可迭代的对象 ...

  7. CAD操作

    1.建立构造线 说签名和图签不在同一条直线上,如何判断两个对向到底是不是在一条线上呢?通过构造线( Construction Line)可以进行判断,CAD中打入: xl 命令,再键入h(horizo ...

  8. Connection failed: NT_STATUS_ACCOUNT_RESTRICTION

    今天在linux机器上想要远程重启一台window的机器,输入命令后报错,如下 Google了下,有说是window禁止远程空密码登录,于是到window系统中添加了密码,这下再运行 这下执行就正常了

  9. sql server 2008 r2 出问题

    1.想利用sql2008的数据挖掘功能,以为是没有安装全,所以就卸载了. (1)利用Windows Installer Clean UP将以前的卸载干净 (2)出现了Could not open ke ...

  10. PHPCURL直接访问JSONRPC服务

    <?php $ch = curl_init(); $url = 'http://localhost/jsonrpc?tm='.time().mt_rand (100,999); //参数是为了防 ...