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. centos安装

    转:http://www.cnblogs.com/Johness/archive/2012/12/03/2800126.html 在已经安装了Win7的系统下安装CentOS 注意:1.由于涉及到对硬 ...

  2. FineUI第十五天---表格概述

    Grid表格概述  跟Asp.Net的差不多. 下面介绍一些属性:  ExpandUnusedSpace:此列充满所有的剩余空间,并且随着表格宽度变化而变化 DataToolTipField:用来显示 ...

  3. Java多线程基础知识(六)

    一. Java中的线程池 线程池的作用: 1. 降低资源消耗 2. 提高响应速度 3. 提高线程的可管理性 线程池处理流程: 1. 线程池判断核心线程池线程是否都在执行任务,如果不是,则创建一个新的工 ...

  4. iOS中多线程原理与runloop介绍

    一.线程概述 有些程序是一条直线,起点到终点:有些程序是一个圆,不断循环,直到将它切断.直线的如简单的Hello World,运行打印完,它的生命周期便结束了,像昙花一现那样:圆如操作系统,一直运行直 ...

  5. PHP面试试题

    1,用PHP打印出前一天的时间,格式是2006-5-10 22:21:21echo date("Y:m:d H:i:s",strtotime("-1 day") ...

  6. 剑指Offer 替换空格

    题目描述 请实现一个函数,将一个字符串中的空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy.   思路: 替换空格,先遍历一遍记 ...

  7. Python自动化之sqlalchemy

    如果该数 据库支持 自增列 ,则 SQLAlchemy 默认 自动 设定 表中第一个 类型 为整形 的主键 为自增列 ORM介绍 orm英文全称object relational mapping,就是 ...

  8. IntelliJ IDEA 创建项目project和module的关系

    使用基于IntelliJ的IDE,如phpstorm.android studio都会对project和module的关系比较糊涂.用简单的一句话来概括是:IntelliJ系中的Project相当于E ...

  9. 除Hadoop大数据技术外,还需了解的九大技术

    除Hadoop外的9个大数据技术: 1.Apache Flink 2.Apache Samza 3.Google Cloud Data Flow 4.StreamSets 5.Tensor Flow ...

  10. NPOI教程

    NPOI 是 POI 项目的 .NET 版本.POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目. NPOI 官方网站:http://npoi.codeplex.com/( ...