时间限制 1000 ms 内存限制 65536 KB Special Judge
题目描述
大家平时都会用到字符串,现在有几种字符串操作,需要你用这几种操作处理下字符串。
HINT
字符串下标从0开始,所有操作的数据范围都合乎规范。
输入格式
多组数据,以EOF结束。
第一行一个字符串,字符串长度大于0,并且小于等于200。
第二行一个数字t,(0<t<=200)。
下面t行,每行表示一种操作。
共有两种操作,每行数据的第一个数表示操作的种类:
翻转操作:第一个是一个数字0,然后两个数字i和len,翻转从下标i长度为len的子串。
替换操作:第一个是一个数字1,然后两个数字i和len,接着一个长度为len的字符串str,用str替换从下标i长度为len的子串。
字符串操作后会更新,旧的字符串被舍弃。(详见sample)
输出格式
每个操作之后输出生成的新的字符串
代码:
#include<iostream>
#include <cstdio>
#include <string>
//#include <algorithm>
#include <vector>
#include<cstring>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
const int MAX=2000;
string s,news;
char a[MAX];
char b[50];
void xuan(int h,int w)
{
//news=s;
int temp;
for(int i=0;i<w;i++)
{
temp=h+w-i-1;
news[h+i]=s[temp];
//cout<<news[i]<<" ";
}
}
void zihuan(int h,int w,char* a)
{
//news=s;
int j=0;
for(int i=h;i<h+w;i++)
{
news[i]=a[j++];
//cout<<news[i]<<" ";
}
}
int main()
{
int n,h,w,num;
while(cin>>s)
{
news=s;
scanf("%d",&num);
while(num--)
{
scanf("%d",&n);
if(n==0)
{
scanf("%d %d",&h,&w);
xuan(h,w);
s=news;
cout<<news<<endl;
}else
{
scanf("%d %d %s",&h,&w,a);
zihuan(h,w,a);
s=news;
cout<<news<<endl;
}
}
}
}