总结 :1 .题意理解
2. 插入要从后往前枚举更新, 删除要从前往后枚举更新数据结构没学好。。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 100005
using namespace std;
int flagOve;
int po, copyPoStart, copyPoEnd;
char ans[maxn];
int l, m;
char update[maxn];
char cop[maxn];
int copLen;
void copyEnd()//OK
{
int L = min(copyPoStart, copyPoEnd), R = max(copyPoStart, copyPoEnd);
copLen = 0;
for(int i = L; i < R; i++) cop[copLen++] = ans[i];
copyPoStart = -1;
}
void L()//OK
{
if(copyPoEnd > 0) copyPoEnd--;
if(po > 0) po--;
}
void R()//Ok
{
if(copyPoEnd < l) copyPoEnd++;
if(po < l) po++;
}
void S()//OK
{
copyPoStart = -1;
flagOve ^= 1;
}
void D()//OK
{
if(copyPoStart != -1)
{
int L = min(copyPoStart, copyPoEnd), R = max(copyPoStart, copyPoEnd);
for(int i = R, j = L; i < l; i++, j++) ans[j] = ans[i];
l -= (R - L);
po = L;
}
else{
for(int i = po; i < l - 1; i++) ans[i] = ans[i + 1];
if(po != l) l--;
}
copyPoStart = -1;
}
void B()//OK
{
copyPoStart = -1;
int pre = po - 1;
if(pre == -1)return ;
else
{
for(int i = pre; i < l - 1; i++) ans[i] = ans[i + 1];
po--;
l--;
}
}
void C() //OK
{
if(copyPoStart != -1) copyEnd();
else
{
copyPoStart = po;
copyPoEnd = po;
}
}
void V()//OK
{
copyPoStart = -1;
if(flagOve)
{
if(copLen + po <= m)
{
for(int i = po; i < copLen + po; i++) ans[i] = cop[i - po];
l = max(l, copLen + po);
po += copLen;
}
}
else
{
if(copLen + l <= m)
{
for(int i = l, j = copLen + l; i >= po; i--, j--) ans[j] = ans[i];
//for(int i = po, j = copLen + po; i < l; i++, j++) ans[j] = ans[i];
for(int i = po; i < po + copLen; i++) ans[i] = cop[i - po];
l += copLen;
po += copLen;
}
}
}
void low(char ss)
{
copyPoStart = -1;
if(flagOve) {
if(po != l){ ans[po] = ss; po++; }
else if(l != m)
{
ans[po] = ss;
po++;
l++;
}
}
else
{
if(l == m)return;
for(int i = l; i > po; i--) ans[i] = ans[i - 1];
ans[po] = ss;
l++;
po++;
}
}
void init()
{
copyPoStart = -1;
po = 0;
l = 0;
copLen = 0;
flagOve = 0;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d %s", &m, update);
init();
for(int i = 0; update[i]; i++)
{
if(update[i] >= 'a' && update[i] <= 'z') low(update[i]);
else if(update[i] == 'L') L();
else if(update[i] == 'R') R();
else if(update[i] == 'S') S();
else if(update[i] == 'D') D();
else if(update[i] == 'B') B();
else if(update[i] == 'C') C();
else if(update[i] == 'V') V();
}
if(l == 0) printf("NOTHING\n");
else
{
for(int i = 0; i < l; i++)printf("%c", ans[i]);
printf("\n");
}
}
return 0;
}