1. 程式人生 > >hrbustoj I.行編輯器(2016級新生程式設計全國邀請賽)

hrbustoj I.行編輯器(2016級新生程式設計全國邀請賽)

Description

這次我們要寫一個簡單的行編輯器,當按下‘#’時代表按下了一次退格符,當按下‘@’時代表一個退行符(使當前行的字元全部無效)。例如,假設從終端接收了這樣的兩行字元:

Whil#lr#e(s#*s)

[email protected](*s=#++)

則實際有效的是下列兩行:

While(*s)

putchar(*s++)

請你編寫一個程式,輸出實際有效的字串。

Input

    第一行是一個整數T,表示測試資料組數。

    接下來每行為一個字串(不含空格和任何空白),表示輸入的原始字串

Output

輸出最終的正確字串。

Sample Input

2

Whil#lr#e(s#*s)

[email protected](*s=#++)

Sample Output

While(*s)

putchar(*s++)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		string s;
		cin>>s;
		int begin=-1;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='@') begin=i; 
		}
		for(int j=begin+1;j<s.size();j++)
		{
			if(s[j+1]!='#') 
			{	
				if(s[j]=='#')  continue;
				cout<<s[j];
			}
		}
		cout<<endl;
	}
	return 0;
}