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

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<cmath> const int maxn=1e5+5;
typedef long long ll;
using namespace std;
string str;
char a[35];
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n,m;
cin>>n>>m;
cin>>str;
for(int t=0;t<26;t++)
{
a[t]='a'+t;
}
string s1,s2;
int vis[35];
for(int t=0;t<m;t++)
{
cin>>s1>>s2;
memset(vis,0,sizeof(vis));
for(int j=0;j<26;j++)
{
if(a[j]==s1[0])
{
vis[j]=1;
a[j]=s2[0];
}
}
for(int j=0;j<26;j++)
{
if(a[j]==s2[0]&&vis[j]==0)
{
a[j]=s1[0];
}
}
}
for(int t=0;t<n;t++)
{
cout<<a[str[t]-'a'];
} return 0;
}

Rebranding(模拟+思维)的更多相关文章

  1. 模拟+思维 HDOJ 5319 Painter

    题目传送门 /* 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最 ...

  2. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  3. Codeforces Round #327 (Div. 2) B. Rebranding 模拟

    B. Rebranding   The name of one small but proud corporation consists of n lowercase English letters. ...

  4. HDU 5538 House Building(模拟——思维)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5538 Problem Description Have you ever played the vi ...

  5. atcoder C - Snuke and Spells(模拟+思维)

    题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...

  6. codeforces 816 C. Karen and Game(模拟+思维)

    题目链接:http://codeforces.com/contest/816/problem/C 题意:给出一个矩阵,问能否从都是0的情况下只将一整行+1或者一整列+1变形过来,如果可以输出需要步数最 ...

  7. CodeForces 625B 字符串模拟+思维

    题意 给出字符串a与b 可以将a中的单个字符改为# 问最少改多少次 a中就找不到b了 一开始想的是用strstr 因为如果找到 可以将strstr(a,b)-a+1改成# 即改首字母 用while循环 ...

  8. UVA 1030 - Image Is Everything【模拟+思维+迭代更新】

    题目链接:uva 1030 - Image Is Everything 题目大意:有一个最大为n*n*n的立方体的一个不规整立体,由若干个1*1*1的小正方体构成(每一个小正方体被涂成不同的颜色),给 ...

  9. UVA 10881 - Piotr's Ants【模拟+思维】

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. vectors 使用应该注意到的问题

    ector1. vector的元素必须具备 assignable和 copyable . 2.vector的迭代器是随机存取迭代器. 3.要考虑到vector的大小(size)和容量(capacity ...

  2. mybatis 框架 的应用之四(一对一 与 一对多)

    lf-driver=com.mysql.jdbc.Driver lf-url=jdbc:mysql://localhost:3306/test?allowMultiQueries=true&u ...

  3. PHP数组的详细解读

    数组的定义 数组的本质是管理和操作一组变量,数组中可以存储任意长度的数据,也可以存储任意类型的数据.数组中的单元称为元素,每个元素包括下标(键)和值,访问元素的时候,是通过下标来访问,包括一维数组,二 ...

  4. sklearn scoring . xgboost.train . ---> rsme

    http://scikit-learn.org/stable/modules/model_evaluation.html#scoring-parameter 3.3.1. The scoring pa ...

  5. hdu 4740 The Donkey of Gui Zhou

    1.扯犊子超多if else 判断的代码,华丽丽的TLE. #include<stdio.h> #include<string.h> #define N 1010 int ma ...

  6. [转]sessionStorage()和localStorage()的用法

    JS的本地保存localStorage.sessionStorage用法总结: 1. localStorage.sessionStorage是Html5的特性,IE7以下浏览器不支持 为什么要掌握lo ...

  7. HTML5移动Web开发实战 PDF扫描版​

    <HTML5移动Web开发实战>提供了应对这一挑战的解决方案.通过阅读本书,你将了解如何有效地利用最新的HTML5的那些针对移动网站的功能,横跨多个移动平台.全书共分10章,从移动Web. ...

  8. Linux中的SELinux与chcon以及Samba实现【转】

    一.SELinux SElinux的前身是NSA(美国国家安全局)发起的一个项目.它的目的是将系统加固到可以达到军方级别. 为什么NSA选择Linux呢? 在目前市面上大多数操作系统都是商用闭源的,只 ...

  9. ASP.Net UpdatePanel控件 局部刷新 && 弹出提示信息

    参考博客: https://blog.csdn.net/qq_35019337/article/details/69972552 https://blog.csdn.net/huangyezi/art ...

  10. 以太坊系列之十六:golang进行智能合约开发

    以太坊系列之十六: 使用golang与智能合约进行交互 以太坊系列之十六: 使用golang与智能合约进行交互 此例子的目录结构 token contract 智能合约的golang wrapper ...