time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Are you going to Scarborough Fair?

Parsley, sage, rosemary and thyme.

Remember me to one who lives there.

He once was the true love of mine.

Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.

Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.

Although the girl wants to help, Willem insists on doing it by himself.

Grick gave Willem a string of length n.

Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.

Grick wants to know the final string after all the m operations.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100).

The second line contains a string s of length n, consisting of lowercase English letters.

Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ nc1, c2 are lowercase English letters), separated by space.

Output

Output string s after performing m operations described above.

Examples
input
3 1
ioi
1 1 i n
output
noi
input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
output
gaaak
Note

For the second example:

After the first operation, the string is wxxak.

After the second operation, the string is waaak.

After the third operation, the string is gaaak.

题意好理解.

代码:

 //A. Scarborough Fair 字符更换
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int N=1e5+;
char s[N];
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
scanf("%s",s);
int len=strlen(s);
while(m--){
char a,b;
int l,r;
cin>>l>>r>>a>>b;
for(int i=l-;i<r;i++){
if(s[i]==a)s[i]=b;
}
}
printf("%s\n",s);
}
return ;
}
 

Codeforces 897 A.Scarborough Fair-字符替换的更多相关文章

  1. Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. codeforces 897A Scarborough Fair 暴力签到

    codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...

  3. Codeforces Round #449 (Div. 2) A. Scarborough Fair【多次区间修改字符串】

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. strtr和str_replace字符替换函数

    (一)strtr是字符替换函数 (1)单个字符替换: <?php echo strtr("abba", "ab", "10"),&qu ...

  5. AC日记——字符替换 openjudge 1.7 08

    08:字符替换 总时间限制:  1000ms 内存限制:  65536kB 描述 把一个字符串中特定的字符全部用给定的字符替换,得到一个新的字符串. 输入 只有一行,由一个字符串和两个字符组成,中间用 ...

  6. SQL 字符替换

    --匹配所有字符替换 )),'被替换','替换') --匹配给定位子替换 update 表名 set 列=stuff(列名,从一开始数位数,往后数几位,替换)

  7. Oracle的字符替换函数translate用法

    参考文档如下:http://www.banping.com/2009/05/18/oracle_function_translate/ Oracle提供了一个字符替换函数translate,不同于re ...

  8. R语言实现两文件对应行列字符替换(解决正负链统一的问题)

    假设存在文件file1.xlsx,其内容如下: 存在文件file2.xlsx,其内容如下: 现在我想从第七列开始,将file2所有的字符替换成file1一样的,即第七.八.九.十列不需要改变,因为fi ...

  9. Python replace() 和 re.sub() 字符串字符替换

    Python replace() 和 re.sub() 字符串字符替换 replace() testStr = 'aa:bb[cc' testStr.replace(':','_') 每次只能替换一个 ...

随机推荐

  1. 四大VDI客户端 总有一款适合你

    [TechTarget中国原创] 交付虚拟桌面时IT管理员必须要考虑到用户如何访问虚拟桌面,因为这会影响用户体验以及VDI部署最终的成败. IT可以转向简便的HTML5客户端,HTML 5客户端功能丰 ...

  2. 你是怎么封装一个view的

    可以通过纯代码或者xib的方式来封装子控件 建立一个跟view相关的模型,然后将模型数据传给view,通过模型上的数据给view的子控件赋值 /** * 纯代码初始化控件时一定会走这个方法 */ - ...

  3. 去掉referer信息

    <iframe src="auto-refresh.html" width=500 height=500 rel="noreferrer">< ...

  4. 【Balanced Binary Tree】cpp

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

  5. APP测试用例要考虑的一些方面

    安装与卸载:●应用是否可以在IOS不同系统版本或android不同系统版本上安装(有的系统版本过低,应用不能适配)●软件安装后是否可以正常运行,安装后的文件夹及文件是否可以写到指定的目录里.●安装过程 ...

  6. 转:sift算法详解

    转自:http://blog.csdn.net/pi9nc/article/details/23302075 对于初学者,从David G.Lowe的论文到实现,有许多鸿沟,本文帮你跨越. 1.SIF ...

  7. oracle定时job粗解

    其中一篇随笔我写了oracle的存储过程大概的介绍,存储过程除了自身有in的param,来进行程序调用处理之外,还可以通过定时任务的方式调用来执行. 应用场景: 数据同步:有两个显示菜单,“信息编辑” ...

  8. 点对点协议(Point-to-Point Protocol)

    简介 点对点协议简称PPP协议,工作在数据链路层.设计目的主要是用来通过拨号或专线方式建立点对点连接发送数据,使其成为各种主机. 网桥和路由器之间简单连接的一种共通的解决方案. PPP协议的组成 建立 ...

  9. H3C交换机端口链路聚合

    H3C交换机端口链路聚合 以太网链路聚合 -- 以太网链路聚合配置命令 -- lacp system-prioritylacp system-priority命令用来配置系统的LACP优先级.undo ...

  10. [bzoj5472] 数列

    Description 输入一个长度为n的数组{ai}(1 <= i <= n) 问有多少个长度为n的数组{xi}(1 <= i <= n),满足1 <= xi < ...