博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符串中字符调换
阅读量:5236 次
发布时间:2019-06-14

本文共 2493 字,大约阅读时间需要 8 分钟。

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 xiby 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 lettersxi and yi.

Output

Print the new name of the corporation.

Sample test(s)
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
 
#include 
#include
using namespace std;const int maxn=2e5+5;char b[maxn];int main(){ int n,m; int a[200]; char x,y; for(int i=0;i<200;i++) a[i]=i; cin>>n>>m; cin>>b; while(m--) { scanf(" %c %c",&x,&y); for(int i='a';i<='z';i++) { if(a[i]==(int)x) { a[i]=(int)y; i++; } if(a[i]==(int)y) a[i]=(int)x; } } for(int i=0;i

 

转载于:https://www.cnblogs.com/chen9510/p/4909405.html

你可能感兴趣的文章
MyBatis课程2
查看>>
桥接模式-Bridge(Java实现)
查看>>
如何破解域管理员密码
查看>>
Windows Server 2008 R2忘记管理员密码后的解决方法
查看>>
IE11兼容IE8的设置
查看>>
windows server 2008 R2 怎么集成USB3.0驱动
查看>>
Foxmail:导入联系人
查看>>
vue:axios二次封装,接口统一存放
查看>>
vue中router与route的区别
查看>>
js 时间对象方法
查看>>
网络请求返回HTTP状态码(404,400,500)
查看>>
Spring的JdbcTemplate、NamedParameterJdbcTemplate、SimpleJdbcTemplate
查看>>
Mac下使用crontab来实现定时任务
查看>>
303. Range Sum Query - Immutable
查看>>
图片加载失败显示默认图片占位符
查看>>
【★】浅谈计算机与随机数
查看>>
解决 sublime text3 运行python文件无法input的问题
查看>>
javascript面相对象编程,封装与继承
查看>>
Atlas命名空间Sys.Data下控件介绍——DataColumn,DataRow和DataTable
查看>>
Java中正则表达式的使用
查看>>