Think:
1知识点:模拟队列+栈
2题意分析:字母输入移动,分别用队列记录输入光标之前内容,用栈记录光标之后可能存在的内容
3其余思路:链表模拟插入结点删除结点
以下为Accepted代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
int op, tp;
char link[1001400], st[1001400];
int main(){
int T, i;
scanf("%d", &T);
while(T--){
op = tp = 0;
stack <char> sta;
while(!sta.empty()){
sta.pop();
}
scanf("%s", st);
int len = strlen(st);
for(i = 0; i < len; i++){
if(st[i] == '-'){
if(tp > 0)
tp--;
}
else if(st[i] == '<'){
if(tp > 0){
sta.push(link[tp-1]);
tp--;
}
}
else if(st[i] == '>'){
if(!sta.empty()){
link[tp++] = sta.top();
sta.pop();
}
}
else {
link[tp++] = st[i];
}
}
bool flag = false;
for(i = 0; i < tp; i++)
printf("%c", link[i]);
while(!sta.empty()){
flag = true;
printf("%c", sta.top());
sta.pop();
}
if(tp || flag)
printf("\n");
}
return 0;
}