codeforces 897 A. Scarborough Fair 【暴力】
来源:互联网 发布:java常见的接口 编辑:程序博客网 时间:2024/04/29 20:07
A. Scarborough Fair
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 ≤ n, c1, 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.
题意: 给你一个长度为n的字符串,然后给你m次修改,每次修改给你一个区间(两端闭),让你把区间内的c1变成c2
分析: 直接暴力
参考代码
#include<bits/stdc++.h>using namespace std;char s[110];int main(){ int n,m;cin>>n>>m; scanf("%s",s+1); int l,r; char a,b; while (m--) { cin>>l>>r>>a>>b; for(int i = l;i <= r;i++) { if(s[i] == a) s[i] = b; } } printf("%s\n",s+1); return 0;}
- 如有错误或遗漏,请私聊下UP,thx
- codeforces 897 A. Scarborough Fair 【暴力】
- Codeforces Round #449 (Div. 2) 897A. Scarborough Fair
- A. Scarborough Fair
- scarborough fair
- scarborough fair
- Scarborough Fair -- Paul Simon
- scarborough fair (song)
- About “Scarborough Fair”
- Scarborough Fair 天籁
- Codeforces897A-Scarborough Fair
- Codeforces897A Scarborough Fair
- Scarborough Fair(斯卡布罗集市)
- CodeForces 864A Fair Game
- 永远的《毕业生》之《Scarborough Fair》
- 《斯加波罗之市》 Scarborough Fair
- 永远的《毕业生》之《Scarborough Fair》
- Scarborough Fair(斯卡布罗集市)歌词赏析
- [天籁之音]《斯卡布罗集市(Scarborough Fair)》
- Locating Restriction Sites
- strong对象,替换 replace,将字符串1转化为字符串2
- 问题解决:DuplicateKeyException: a different object with the same identifier value
- Leetcode 算法设计 第十四周
- WebService返回XML文件自定义格式
- codeforces 897 A. Scarborough Fair 【暴力】
- 用两栈和两队列实现简易停车场管理系统
- tornado4.5.2HTTP请求及响应流程
- Docker 安装 MongoDB 3.x
- 回溯法-5.3批处理作业调度
- cmd命令
- (一)python的可变与不可变数据类型
- kotlin开发Android入门篇二流程控制
- Handler 更新UI