Hihooder 1228
题目链接:
http://hihocoder.com/problemset/problem/1228
题意:
自己看……写完题意估计就死这了
思路:
大模拟。
主要考察了string的用法,比赛的时候由于不会用string吃了很大亏,刚开始还写了发链表的然后就全部推掉重新写了……
String主要有几个比较常用的函数:
string str = “”; ///声明一个string,初始化为空
str.substr(int pos, int len) ///求出以第pos个位置(从0开始)的包含n个字符的子串
str.length(); ///求长度
源码:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <climits>
#include <cassert>
#include <cmath>
#include <string>
#include <bitset>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#define LL long long
#define gmax(a,b) ((a) > (b) ? (a) : (b))
#define gmin(a,b) ((a) < (b) ? (a) : (b))
#define MOD (1000000007)
using namespace std;
const int MAXN = 100000 + 5;
string str;
int now, len;
char data[MAXN];
string strC, strtemp;
int m;
void solve1(char c, int flag) {
string Le = str.substr(0, now);
string Ri = str.substr(now, len - now);
if(flag == 1) {
if(len + 1 > m) return; ///
str = Le + c + Ri;
// len++;
now++;
} else {
if((int)Ri.length() > 0)
Ri[0] = c;
else if(len + 1 <= m)
Ri = Ri + c;//, len++;
else
return;
str = Le + Ri;
now++;
}
}
void solveL() {
if(now < 1)
return;
now--;
}
void solveR() {
if(now >= len) return;
now++;
}
void solveB() {
if(now == 0) return;
string Le = str.substr(0, now);
string Ri = str.substr(now, len - now);
str = str.substr(0, now - 1) + str.substr(now, len - now);
now--;
//len--;
}
void solveC(int &reC, int &flagC) {
// printf("reC = %d, now = %d\n", reC, now);
if(flagC == 1) {
reC = now ;
}
else {
if(reC < now ) {
strC = str.substr(reC , now-reC);
} else if(reC >= now ) {
strC = str.substr(now , reC-now);
}
}
flagC = -flagC;
}
void solveD(int reC, int flagC) {
string Le = str.substr(0, now);
string Ri = str.substr(now, len - now);
if(flagC == 1) {
// printf("now = %d, len = %d\n", now, len);
if(now < len){
str = Le + str.substr(now + 1, len - now - 1);
// len--;
}
}
if(flagC == -1) {
// printf("now = %d, reC = %d\n", now, reC);
if(now < reC) {
str = str.substr(0, now) + str.substr(reC, len - reC);
// len -= reC - now ;
} else if(now > reC){
str = str.substr(0, reC) + str.substr(now, len - now);
// len -= now - reC;
now = reC;
}
}
}
void solveV(int flag) {
string Le = str.substr(0, now);
string Ri = str.substr(now, len - now);
if(flag == 1) {
// cout<<strC<<"*()"<<endl;
// cout<<now<<" ()()"<<reC<<endl;
if(len + (int)strC.length() > m) return;
str = Le + strC + Ri;
now += strC.length();
// len += strC.length();
} else {
int tt = strC.length();
// cout<<strC<<" *********"<<endl;
if(now + max(len - now, tt) > m) return;
if((int)strC.length() >= (int)Ri.length()){
str = Le + strC;
// len = str.length();
// now = str.length();
}
else{
str = Le + strC + Ri.substr(tt , len - now - tt);
// now += tt;
}
now += strC.length();
}
}
int main() {
// freopen("1002.in" , "r", stdin);
int t;
scanf("%d", &t);
while(t--) {
scanf("%d%s", &m, data);
int L = strlen(data);
int flag1 = 1; ///for mode
int flagC = 1; ///for D
int reC = 0;
len = now = 0;
str="";
strC = "";
for(int i = 0 ; i < L ; i++) {
len = str.length();
if(data[i] >= 'a' && data[i] <= 'z') {
solve1(data[i], flag1), flagC = 1;
} else if(data[i] == 'L') {
solveL();
} else if(data[i] == 'R') {
solveR();
} else if(data[i] == 'B') {
solveB(), flagC = 1;
} else if(data[i] == 'S') {
flag1 = -flag1, flagC = 1;
} else if(data[i] == 'D') {
solveD(reC, flagC), flagC = 1;
} else if(data[i] == 'V') {
solveV(flag1), flagC = 1;
} else if(data[i] == 'C') {
solveC(reC, flagC);
}
// printf("len = %d, now = %d, op = %c\n", now, len, data[i]);
// cout << str << endl;
}
if(str=="")puts("NOTHING");
else
cout<<str<<endl;
}
return 0;
}