博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 591 B Rebranding【Codeforces Round #327 (Div. 2)】
阅读量:6503 次
发布时间:2019-06-24

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

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.

Sample test(s)
Input
6 1policep m
Output
molice
Input
11 6abacabadabaa bb ca de gf ab b
Output
cdcbcdcfcdc
Note

In the second sample the name of the corporation consecutively changes as follows:

题目大意:

首先给定两个数 m, n 和一个字符串,m : 字符串的长度,n:表示有 n 行,

然后有两个字符 s ,t ,表示可以将字符s 转化为 t。 也可以将字符t 转化为 s,

求最后转化后的字符串并输出。。。

解题思路:

首先将26个英文小写字母用一个数组a【】表示,下标为其所代表的ASCII码,

然后只需要从 字符串 a 循环到 z就行了,如果遇到s 和 t就直接代替,并且将a【】数组中的 s 所对应的ASCII码

改为 t代表的就行了。。

上代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MM(a) memset(a,0,sizeof(a))typedef long long LL;typedef unsigned long long ULL;const int maxn = 2*1e5+5;const int mod = 1000000007;const double eps = 1e0-7;char arr[maxn];char a[300];void Init(){ for(char i='a'; i<='z'; i++) a[(int)i] = i;}int main(){ int m, n; cin>>m>>n>>arr; Init(); while(n--) { char s, t; cin>>s>>t; for(char i='a'; i<='z'; i++) { if(s == a[(int)i]) a[(int)i] = t; else if(t ==a[(int)i]) a[(int)i] = s; } } for(int i=0; i

转载地址:http://nbhyo.baihongyu.com/

你可能感兴趣的文章
linux 淘宝开源监控工具tsar
查看>>
JavaScript 新语法详解:Class 的私有属性与私有方法 ...
查看>>
Java性能优化之JVM GC(垃圾回收机制)
查看>>
积累各种好的链接
查看>>
如何在招聘中考核.NET架构师
查看>>
zabbix3.2监控linux磁盘IO
查看>>
长三角G60科创走廊智能驾驶产业联盟揭牌成立,近80家企业助力智能驾驶行业发展 ...
查看>>
Semaphore
查看>>
k8s使用glusterfs实现动态持久化存储
查看>>
我们雇佣了一只大猴子...
查看>>
2017-12-24 手机编程环境初尝试-用AIDE开发Android应用
查看>>
pyqt5的下载进度条 实现模板
查看>>
Flink1.7.2 local WordCount源码分析
查看>>
盘点抖音源码中的广告变现方式
查看>>
星际荣耀获鼎晖投资A+轮投资,上半年将进行首枚入轨运载火箭
查看>>
Linux基础命令---显示路由表route
查看>>
金三银四,2019大厂Android高级工程师面试题整理
查看>>
SSL证书过期替换之踩坑总结
查看>>
全栈必备 Java 基础
查看>>
PostgreSQL 快速给指定表每个字段创建索引 - 1
查看>>