题意:
类似于python的切片操作,每次会告诉你将某个区间用某些数字代替,代替前输入这个区间内的数。
题目很恶心,没说格式问题,输入中数字可能使用空格隔开也可能是用逗号隔开,而且不一定像它给的,逗号后面还有空格,所以要注意这个问题。
//Time:0ms
//Memory:23720KB
//Length:1191B
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;
#define MAXN 3000010
int arr[MAXN],tmp[MAXN],n;
char str[100010];
void tol(int l,int r,int len)
{
for(int i=l;i<r;++i) arr[i-len]=arr[i];
n-=len;
}
void tor(int l,int r,int len)
{
for(int i=r-1;i>=l;--i) arr[i+len]=arr[i];
n+=len;
}
bool got(int &pos,int &num)
{
bool flag=0,ty=0;
num=0;
while(str[pos]&&(str[pos]<'0'||str[pos]>'9')&&str[pos]!='-') ++pos;
if(str[pos]=='-') ++pos,ty=1;
while(str[pos]&&str[pos]>='0'&&str[pos]<='9')
{
flag=true;
num=num*10+str[pos]-'0';
++pos;
}
if(ty) num=-num;
return flag;
}
int main()
{
//freopen("/home/moor/Code/input","r",stdin);
n=0;
while(gets(str)!=NULL)
{
int a,b,top=0,pos=0;
istringstream is(str);
got(pos,a);
got(pos,b);
for(int i=a,s=0;i<b;++i) printf("%s%d",s?", ":"",arr[i]),s=1;
printf("\n");
while(got(pos,tmp[top])) ++top;
if(top>b-a) tor(b,n,top-b+a);
else if(top<b-a) tol(b,n,b-a-top);
for(int i=0;i<top;++i) arr[i+a]=tmp[i];
}
return 0;
}