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(':','_') 每次只能替换一个 ...
随机推荐
- python学习笔记三:函数及变量作用域
一.定义 def functionName([arg1,arg2,...]): code 二.示例 #!/usr/bin/python #coding:utf8 #coding=utf8 #encod ...
- 【Linux命令】删除大文件后磁盘空间未释放问题
前言 工作中经常遇到Linux系统磁盘空间不足,但是删除后较大的日志文件后,发现磁盘空间仍没有被释放,有点摸不着头脑,今天博主带大家解决这个问题. 思路 1.工作发现磁盘空间不足: 2.找到占用磁盘空 ...
- ASP.NET Core 2.1 源码学习之 Options[2]:IOptions 【转】
原文链接:https://www.cnblogs.com/RainingNight/p/strongly-typed-options-ioptions-in-asp-net-core.html 在 上 ...
- 孤荷凌寒自学python第四十二天python线程控制之Condition对象
孤荷凌寒自学python第四十二天python的线程同步之Condition对象 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天学习了Condition对象,发现它综合了Event对象 ...
- CSU-1986 玄学
题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=1986 题目 Description 阴阳师子浩君,最近从<初等数论 ...
- ArcGIS 创建要素时提示“表已经被注册(table already registered)”
今天一位实施大哥在ArcCatalog中要重建一个要素类,所以就在ArcCatalog中连接上Oracle数据库,直接删除了要素类,然后重新创建了一个新的要素类,可是却报错“表已经被创建”,并提示不可 ...
- 【Nescafé 31】杯NOIP模拟赛
t1 题意:n*m的棋盘上从(1,1)走到(n,m),只能向下或向右,一些格子有老鼠,每个老鼠互不相同,当处于与老鼠有重边的格子时,视为看见了这只老鼠,求到终点看到最少的不同老鼠数. 分析:DP 由于 ...
- POJ 1039 Pipe | 线段相交
题目: 给一个管子,有很多转弯处,问从管口的射线射进去最长能射到多远 题解: 根据黑书,可以证明的是这条光线一定经过了一个上顶点和下顶点 所以我们枚举每对上下顶点就可以了 #include<cs ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- Python 二进制,十进制,十六进制转换
十六进制 到 十进制 使用 int() 函数 ,第一个参数是字符串 '0Xff' ,第二个参数是说明,这个字符串是几进制的数. 转化的结果是一个十进制数. >>> int('0xf ...