Codeforces Round #327 (Div. 2) B. Rebranding 模拟
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.
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.
Print the new name of the corporation.
6 1
police
p m
molice
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define inf 100000007
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
#define maxn 200000+5
char a[maxn],A[maxn],B[maxn];
int b[maxn];
int main()
{
int n=read(),m=read();
scanf("%s",a);
for(int i=;i<;i++){
b[i]=i;
}
for(int i=;i<=m;i++){
scanf("%s%s",A,B);
if(A[]==B[])continue;
for(int j=;j<;j++){
if(B[]==b[j]+'a'){
b[j]=A[]-'a';
} else if(A[]==b[j]+'a'){
b[j]=B[]-'a';
}
}
}
for(int i=;i<n;i++){
printf("%c",b[a[i]-'a']+'a');
}
cout<<endl;
return ;
}
代码
Codeforces Round #327 (Div. 2) B. Rebranding 模拟的更多相关文章
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
- 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 ...
- Codeforces Round #327 (Div. 2) B Rebranding(映射)
O(1)变换映射,最后一次性替换. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; char s[ ...
- 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 ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...
- Codeforces Round #398 (Div. 2) A. Snacktower 模拟
A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...
- Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing
http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...
随机推荐
- java 基础学习笔记 - 安装
1. 从www.sun.com中 下载jdk安装包 2. 执行安装包,安装jdk ,jre(Java运行环境) 3. 配置path路径 增加jdk下的bin目录. 配置完后需要重启cmd窗口,因为cm ...
- Filesystem Hierarchy Standard (Unix, Linux etc)
http://www.pathname.com/fhs/ /boot -- Static files of the boot loader Purpose: contains everything r ...
- 梦想CAD控件事件COM接口知识点
一.鼠标事件 _DMxDrawXEvents::MouseEvent 控件中的鼠标事件. 参数 说明 LONG lType 事件类型,1鼠标移动,2是鼠标左键按下,3是鼠标右键按下,4是鼠标左键双击 ...
- docker在ubuntu16.04下的安装及阿里云镜像的配置
1.获取最新版本的 Docker 安装包 anmin@ubuntu:~$ wget -qO- https://get.docker.com/ | sh 安装完成后有个提示: If you would ...
- 这段代码很Pythonic | 相见恨晚的 itertools 库
前言 最近事情不是很多,想写一些技术文章分享给大家,同时也对自己一段时间来碎片化接受的知识进行一下梳理,所谓写清楚才能说清楚,说清楚才能想清楚,就是这个道理了. 很多人都致力于把Python代码写得更 ...
- php第二十六节课
会话购物车 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- JavaScript day1(注释)
JavaScript中的注释方式有两种: 单行注释,使用 //. // This is an in-line comment. 多行注释,以/*开始,用*/来结束. /* This is a mult ...
- Configure a proxy for your API calls with Angular CLI
Table of contents Local development setup with Angular Issue: Dev server plus backend API Configurin ...
- [USACO] 奶牛混合起来 Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- 转来的--轻松自动化---selenium-webdriver(python) (七)---定位iframe——转来的
本节知识点: 多层框架或窗口的定位: switch_to_frame() switch_to_window() 智能等待: implicitly_wait() 对于一个现代的web应用,经常会出现框架 ...