Codeforces Round #327 (Div. 2)B(逻辑)
2 seconds
256 megabytes
standard input
standard output
The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired m designers. Once a company hires the i-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters xi by yi, and all the letters yi by xi. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that xi coincides with yi. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of n lowercase English letters and represents the original name of the corporation.
Next m lines contain the descriptions of the designers' actions: the i-th of them contains two space-separated lowercase English letters xi and yi.
Print the new name of the corporation.
6 1
police
p m
molice
11 6
abacabadaba
a b
b c
a d
e g
f a
b b
cdcbcdcfcdc
In the second sample the name of the corporation consecutively changes as follows:






题意:
给出一个长为n的字符串a[],进行m次操作;
每次操作描述为将字符a改成字符b,将字符b改成字符a;
思路:
开一个字符数组str存储a...z26个字符。。直接对str里面的字符进行交换操作。。
然后用a[i]-"a"做下标。。str[a[i]-"a"]即为交换后的字符。。
代码:
#include <bits/stdc++.h>
using namespace std; int main(void)
{
std::ios::sync_with_stdio(false);
int n, m;
string a;
cin >> n >> m >> a;
char str[];
for(int i=; i<; i++)
str[i]=i+'a';
while(m--)
{
char a, b;
cin >> a >> b;
if(a==b) continue;
for(int i=; i<; i++)
{
if(str[i]==a) str[i]=b;
else if(str[i]==b) str[i]=a;
}
}
for(int i=; i<a.size(); i++)
cout << str[a[i]-'a'];
cout << endl;
return ;
}
Codeforces Round #327 (Div. 2)B(逻辑)的更多相关文章
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #327 (Div. 2) E. Three States BFS
E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...
- Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理
D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
- Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing
http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...
- Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...
- Codeforces Round #327 (Div. 2)
题目传送门 水 A - Wizards' Duel 题目都没看清就写了,1e-4精度WA了一次... /************************************************ ...
- Codeforces Round #327 (Div. 2)-Wizards' Duel
题意: 在一条长度为l的走廊,两个人站在走廊的左右两端分别以p,q的速度走来,问他们相遇时离左端的距离是多少? 思路: 非常简单的暴力题,不解释. 代码如下: #include <iostrea ...
随机推荐
- 弹窗插件 popup.js 完美修正版
作为信息展示弹出窗口,很有用!是一个js插件,不是jQuery插件! 地址:http://img.jb51.net/online/popup/popup.html
- iOS开发——常见错误——使用MJRefresh返回上一个界面蹦掉的情况
最近在使用MJRefresh框架时发现了一个bug 下面是我的源代码 前一个界面 -(void)tableView:(UITableView *)tableView didSelectRowAtInd ...
- 修复 VirtualBox 下 Ubuntu 14.10 屏幕分辨率问题
在 Windows 7 下使用 VirtualBox 安装了一个 Ubuntu 14.10 后,碰到了一个 640×480 屏幕分辨率的问题. 在 ‘Display Settings' 设置界面的 ‘ ...
- HTTP头部详解
因为之后的HTTP头注入要学习这些所以就看了.觉得很不错,算是学习前的科普. <HTTP头部详解>转载自:http://www.cnblogs.com/lcamry/p/5763040.h ...
- VMware vCenter Server安装图解教程
安装说明: 1.安装VMware vCenter Server的主机操作系统为:Windows Server 2008 R2 2.在Windows Server 2008 R2中需要预先安装好SQL ...
- SPOJ 375 Query on a tree
Description 给出一个树,每条边有边权,支持两种操作,询问 \(u,v\) 路径上边权最大值,修改第 \(i\) 条边的边权,\(n\leqslant 10^4,T\leqslant 10\ ...
- svn下目录说明
Branch 目录 : 该SVN 的Branch目录下存放的是:跟工程项目相关的各个工程版本分支.该目录下面的版本分支可能会被修改合并.不是稳定的版本. Document 目录:该SVN 的Docum ...
- web图片轮播实现
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 【smarty项目源码】模拟smarty模版文件的解析过程
<?php class MyMiniSmarty{ //模版文件的存放路径 var $template_dir="./templates/"; //编译文件的存放路径 ,编译 ...
- MD5 加密字符串
public class MD5 { /*** * MD5加码 生成32位md5码 */ public static String string2MD5(String inStr){ MessageD ...