UVA 12897 Decoding Baby Boos 暴力
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 暴力的更多相关文章
- UVA12897 - Decoding Baby Boos
没必要每次都真的修改一遍字母值,用一个标记表示字母最后的值,最后一遍的时候再进行修改 #include<cstdio> #include<cstring> +; char st ...
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- UVA.10986 Fractions Again (经典暴力)
UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...
- UVA 270 Lining Up 共线点 暴力
题意:给出几个点的位置,问一条直线最多能连过几个点. 只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可. 我这样做过于暴力,2.7s让人心惊肉跳...应该还能继续剪枝的,同一直线找过之后 ...
- uva 10825 - Anagram and Multiplication(暴力)
题目链接:uva 10825 - Anagram and Multiplication 题目大意:给出m和n,要求找一个m位的n进制数,要求说该数乘以2~m中的随意一个数的结果是原先数各个位上数值的一 ...
- UVa 11210 Chinese Mahjong (暴力,递归寻找)
题意:这个题意.有点麻烦,就是说给定13张牌,让你求能“听”的牌.(具体的见原题) 原题链接: https://uva.onlinejudge.org/index.php?option=com_onl ...
- UVa 11059 最大乘积 java 暴力破解
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVa 817 According to Bartjens (暴力,DFS)
题意:给出一个数字组成的字符串,然后在字符串内添加三种运算符号 * + - ,要求输出所有添加运算符并运算后结果等于2000的式子. 所有数字不能有前导0, 且式子必须是合法的. 析:这个题很明显的暴 ...
- UVA 10976 分数拆分【暴力】
题目链接:https://vjudge.net/contest/210334#problem/C 题目大意: It is easy to see that for every fraction in ...
随机推荐
- Redis pipeline and list
Redis Redis 是一个开源的基于内存的数据结构存储器.通常可作为数据库,缓存和消息中介.它支持的数据结构有:字符串.哈希表.列表.集合.支持范围查询的有序集合.位图.hyperloglogs和 ...
- Locker
题意: 有2个数字串,每次可以变化1-3位(每位+1或-1(0-9,9-0)可循环),求由1串变到2串的最小用的次数. 分析: dp[i][num]表示变到第i位时最后两位组成的数是num时最小次数( ...
- 记录一次cefsharp1输入法在win7下异常解决定位
最近几天都被基于cefSharp封装的浏览器控件搞疯了!对于cefSharp基本满足当前所做项目的需求,但是有一个问题一直困扰我,那就是系统中偶尔会出现输入法不能转换到中文.而且这个问题似乎没有什么规 ...
- 2014搜狗前端面经【B事业部】
本来就投了一份简历,后来又收到了个B事业部的面试电话,今天刚面完一面,总体感觉还是很基础的,其中一名面试官帅到不行啊!另一个也不差,真是幸胡...(sorry,跑题了...) 上来先做了份笔试题,超级 ...
- MVC用户登录方法(lamda表达式)
public bool ValidateUser(account model) { using (assertEntities db = new assertEntities()) { acc ...
- 数据结构 -- 图的最短路径 Java版
作者版权所有,转载请注明出处,多谢.http://www.cnblogs.com/Henvealf/p/5574455.html 上一篇介绍了有关图的表示和遍历实现.数据结构 -- 简单图的实现与遍历 ...
- C#修改下拉框选项的高度
重写ListBox.DrawItem事件处理,别忘记将ListBox.DrawMode 设置为OwnerDrawVariable,ListBox.ItemHeight值改大一点,字体也适当放大一号. ...
- S3
S3是Amazon EMR的一部分,它提供了一些Wikipedia的浏览统计数据,这些浏览数据的格式便于Spark测试.
- Django Signals 从实践到源码分析(转)
原文:http://foofish.net/blog/66/django-signals 当某个事件发生的时候,signal(信号)允许senders(发送者)用来通知receivers(接收者),通 ...
- New Objective-C Feature
[Advance Objective-C Feature] 1.@import避免反复解析头文件,本地宏对框架API定义无影响. 2.可以导入单独一个头文件. 3.使用了@import后,不再需要选择 ...