B. Rebranding
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the new name of the corporation.

Examples
Input
6 1
police
p m
Output
molice
Input
11 6
abacabadaba
a b
b c
a d
e g
f a
b b
Output
cdcbcdcfcdc
Note

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(逻辑)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

  6. Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing

    http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...

  7. 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 ...

  8. Codeforces Round #327 (Div. 2)

    题目传送门 水 A - Wizards' Duel 题目都没看清就写了,1e-4精度WA了一次... /************************************************ ...

  9. Codeforces Round #327 (Div. 2)-Wizards' Duel

    题意: 在一条长度为l的走廊,两个人站在走廊的左右两端分别以p,q的速度走来,问他们相遇时离左端的距离是多少? 思路: 非常简单的暴力题,不解释. 代码如下: #include <iostrea ...

随机推荐

  1. 从程序员到CTO的Java技术路线图

    转自:http://zz563143188.iteye.com/blog/1877266 企业级项目实战地址:http://zz563143188.iteye.com/blog/1825168 开发资 ...

  2. Nginx的作用

    负载均衡 现在几乎看不到单机奋斗的应用了吧.反向代理服务器可以根据负载均衡算法进行均匀或者自定义的转发.常见的负载均衡算法有:轮转算法(Round Robin).最少连接算法(Least Connec ...

  3. linux 下安装tomcat

    1.把安装包放到 tomcat的目录, 2.然后  解压  tar -zxvf apache-tomcat-7.0.70.tar.gz    解压. 3.然后启动tomcat

  4. js 判断鼠标进去方向

    function fx(id){ var obj= document.getElementById(id); var fun=function(e){ var w=obj.offsetWidth; v ...

  5. (七)理解angular中的module和injector,即依赖注入

    (七)理解angular中的module和injector,即依赖注入 时间:2014-10-10 01:16:54      阅读:63060      评论:1      收藏:0      [点 ...

  6. 单臂路由与三层交换机实现VLAN通信

    不同VLAN之间相互通信的两种方式 (单臂路由.三层交换) 试验环境:东郊二楼第三机房 试验设备:Catalyst 2950-24(SW3)                   Cisco 2611( ...

  7. 架构Android App总结

    历时两个多月,自己架构的一个App快要完成了,有很多可以总结的地方: 1, 各个模块尽可能独立,不要直接调用,用消息机制解耦.包括页面跳转不要直接startActivity,而是用消息跳转:业务模块请 ...

  8. HTTP协议概念篇

    1.概念 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器. ...

  9. django xadmin 外键

    style_fields = {'db栏位名称': "fk-ajax"} 实体关系: Account (*)-->(1) user 表单控件: 下拉框 美化用了selecti ...

  10. MySQL一次插入多行数据

    CREATE TABLE `viewhistory` ( `viewid` ) NOT NULL AUTO_INCREMENT, `uid` ) NOT NULL, `video` ) NOT NUL ...