Codeforces Round #449 (Div. 2) A-C题解
来源:互联网 发布:尼崎事件 知乎 编辑:程序博客网 时间:2024/06/05 11:39
又一次涨分,虽然上次也在涨分,但没心情写博客,就做出一个题,补题体验感也不好,这次C题看了一个半小时没做出来,真是水的可以。
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] (froml-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 1ioi1 1 i n
noi
5 3wxhak3 3 h x1 5 x a1 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.
题意通俗易懂,就是找到一个区间,找到相同的字符,就换成另一个字符,模拟即可。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<set>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}string map;int main(){int n,m,i,j,k,x,y;char c1,c2;cin>>n>>m;cin>>map;for(j=0;j<m;j++){cin>>x>>y>>c1>>c2;for(i=x-1;i<=y-1&&map[i];i++){if(map[i]==c1)map[i]=c2;}}cout<<map<<endl;}
- Codeforces Round #449 (Div. 2) A-C题解
- Codeforces Round #241 (Div. 2) A B C题解
- Codeforces Round #292 (Div. 2) A,B,C,D 题解
- Codeforces Round #304 (Div. 2) A,B,C题解
- Codeforces Round #364 (Div. 2)(A,B,C,D) 题解
- Codeforces Round #377 (Div. 2)部分题解A+B+C!
- Codeforces Round #388 (Div. 2) A,B,C,D 题解
- Codeforces Round #395 (Div. 2) A,B,C,D 题解
- Codeforces Round #429 (Div. 2) A-C题解
- Codeforces Round #435 (Div. 2) A-C题解+D代码
- Codeforces Round #436 div 2 A B C D 题解
- Codeforces Round #439 (Div. 2) A-C题解
- Codeforces Round #439 (Div. 2) A-C题解
- Codeforces Round #443 (Div. 2) A-C 题解
- Codeforces Round #444 (Div. 2) A-C 题解
- Codeforces Round #446 (Div. 2) A-C 题解
- Codeforces Round #447 (Div. 2) A-C题解
- Codeforces Round #450 (Div. 2) A-C题解
- 树结构中的节点增删改操作后,排序码的重新设置
- selectKey 这个标签主要用于Insert数据时不支持主键自动生成的问题
- 重复子串-LintCode
- java日期工具类1
- 关于计算整数是不是偶数奇数的理解
- Codeforces Round #449 (Div. 2) A-C题解
- MyBatis之java.lang.UnsupportedOperationException异常解决方案
- 禁止 上滑下滑的时候出现微信浏览器的黑色背景
- 批量删除
- Git,GitLab,GitHub,SVN ,CVS,VSS,码云的安装,用法,区别,进阶
- 进程管理API之get_task_pid
- RxJava+Retrofit结合使用(小案例)
- 前端性能优化
- 同一台机器上利用FTP上传文件