Codeforces 897 A.Scarborough Fair-字符替换
2 seconds
256 megabytes
standard input
standard output
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.
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 ≤ n, c1, c2 are lowercase English letters), separated by space.
Output string s after performing m operations described above.
3 1
ioi
1 1 i n
noi
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
gaaak
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-字符替换的更多相关文章
- 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 ...
- codeforces 897A Scarborough Fair 暴力签到
codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...
- 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 ...
- strtr和str_replace字符替换函数
(一)strtr是字符替换函数 (1)单个字符替换: <?php echo strtr("abba", "ab", "10"),&qu ...
- AC日记——字符替换 openjudge 1.7 08
08:字符替换 总时间限制: 1000ms 内存限制: 65536kB 描述 把一个字符串中特定的字符全部用给定的字符替换,得到一个新的字符串. 输入 只有一行,由一个字符串和两个字符组成,中间用 ...
- SQL 字符替换
--匹配所有字符替换 )),'被替换','替换') --匹配给定位子替换 update 表名 set 列=stuff(列名,从一开始数位数,往后数几位,替换)
- Oracle的字符替换函数translate用法
参考文档如下:http://www.banping.com/2009/05/18/oracle_function_translate/ Oracle提供了一个字符替换函数translate,不同于re ...
- R语言实现两文件对应行列字符替换(解决正负链统一的问题)
假设存在文件file1.xlsx,其内容如下: 存在文件file2.xlsx,其内容如下: 现在我想从第七列开始,将file2所有的字符替换成file1一样的,即第七.八.九.十列不需要改变,因为fi ...
- Python replace() 和 re.sub() 字符串字符替换
Python replace() 和 re.sub() 字符串字符替换 replace() testStr = 'aa:bb[cc' testStr.replace(':','_') 每次只能替换一个 ...
随机推荐
- elasticsearch索引和映射
目录 1. elasticsearch如何实现搜索 1.1 搜索实例 1.2 es中数据的类型 1.3 倒排索引 1.4 分析与分析器 1.4.1 什么是分析器 1.4.2 内置分析器种类 1.4.3 ...
- 剑指Offer - 九度1387 - 斐波那契数列
剑指Offer - 九度1387 - 斐波那契数列2013-11-24 03:08 题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.斐波那契数列的定义如下: ...
- Pythonyield使用浅析
转自:https://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ 您可能听说过,带有 yield 的函数在 Python ...
- SQL 与关系代数
Table of Contents 前言 关系与表 关系代数的基本运算 投影 选择 并运算 集合差运算 笛卡尔积 更名运算 关系代数的附加运算 集合交运算 连接运算 自然连接 内连接 外连接 结语 前 ...
- badboy录制提示当前页面的脚本发生错误
利用badboy录制时,发生了错误: 网上查了查,说badboy默认使用IE浏览器,打开Internet选项—>高级,图中的两个选项不要勾选即可 然鹅,然鹅,并没有作用... 请教了好心的同行, ...
- 【转载】Unity3D研究院transform.parent = parent坐标就乱了
昨天有朋友问我了一个问题,它将Hierarchy视图里的某个子节点下的GameObject拷贝到另外一个对象的子节点下面,他使用的方法就是 transform.parent = parent 但是拷贝 ...
- CodeForces-757B Bash's Big Day
题目链接 https://vjudge.net/problem/CodeForces-757B 题目 Description Bash has set out on a journey to beco ...
- 课时40:类与对象:一些相关的BIF
目录: 一.一些相关的BIF 二..课时40课后习题及答案 ********************** 一.一些相关的BIF ********************** 1.issubclass( ...
- 转:sift算法详解
转自:http://blog.csdn.net/pi9nc/article/details/23302075 对于初学者,从David G.Lowe的论文到实现,有许多鸿沟,本文帮你跨越. 1.SIF ...
- [转] mysql分区性能初探
本文转自:http://www.cnblogs.com/acpp/archive/2010/08/09/1795464.html 一, 分区概念 分区允许根据指定的规则,跨文件系统分配单个 ...