题目链接
C++代码
#include<bits/stdc++.h>
using namespace std;
void Replace(char s[], int x,int y, char s2[])
{
for(int i = x; i <= y; i ++)s[i] = s2[i - x];
return ;
}
void Print(char s[], int x, int y)
{
for(int i = x; i <= y; i ++)printf("%c", s[i]);
printf("\n");
return ;
}
void Reverse(char s[], int x,int y)
{
int mid = (x + y) / 2;
for(int i = x; i <= mid; i ++)swap(s[i], s[x + y - i]);
return ;
}
int main()
{
char s[1005];
scanf("%s", s);
int tt;
scanf("%d", &tt);
getchar();
while(tt --)
{
char s1[1005], s2[1005];
int x, y;
scanf("%[^\n]", s2);
getchar();
sscanf(s2, "%[a-z]", s1);
if(strcmp("replace", s1) == 0)
{
char s3[1005];
sscanf(s2, "%[a-z] %d %d %s", s1, &x, &y, s3);
Replace(s, x, y ,s3);
}
else if(strcmp("print", s1) == 0)
{
sscanf(s2, "%[a-z] %d %d", s1, &x, &y);
Print(s, x, y);
}
else if(strcmp("reverse", s1) == 0)
{
sscanf(s2, "%[a-z] %d %d", s1, &x, &y);
Reverse(s, x, y);
}
}
return 0;
}
|