Description
Early computer used line editor, which allowed text to be created and changed only within one line at a time. However, in line editor programs, typing, editing, and document display do not occur simultaneously (unlike the modern text editor like Microsoft Word). Typically, typing does not enter text directly into the document. Instead, users modify the document text by entering simple commands on a text-only terminal.
Here is an example of a simple line editor which can only process English. In addition, it has two commands. ‘@’ and ‘#’. ‘#’ means to cancel the previous letter, and ‘@’ is a command which invalidates all the letters typed before. That is to say, if you want type “aa”, but have mistakenly entered “ab”, then you should enter ‘#a’ or ‘@aa’ to correct it. Note that if there is no letter in the current document, ‘@’ or ‘#’ command will do nothing.
Input
The first line contains an integer T, which is the number of test cases. Each test case is a typing sequence of a line editor, which contains only lower case letters, ‘@’ and ‘#’.
there are no more than 1000 letters for each test case.
Output
For each test case, print one line which represents the final document of the user. There would be no empty line in the test data.
Sample Input2
Sample Output
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int y,n;
string str;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
cin>>str;
y=-1;
for(int j=str.length()-1; j>=0; j--)//找到@字符的位置
{
if(str[j]=='@')
{
y=j;
break;
}
}
str.erase(0,y+1);//删除@前面所有字符
//cout<<str<<endl;
for(int j=1; j<str.length(); j++)
{
if(str[j]=='#')//是#就删除 它 和 它前面字符(两个都要删除)
{
str.erase(j-1,2);
j=j-2;//删除之后字符串长度会改变,记得减去2
if(j<0)//如果变成了负数,从0开始即可,不然会指向空地址,报错
j=0;
}
//cout<<j<<" "<<str.length()<<endl;
}
while(str[0]=='#')
str.erase(0,1);
cout<<str<<endl;
}
return 0;
}