题目链接:点击打开链接
行编辑器 | ||||||
| ||||||
Description | ||||||
这次我们要写一个简单的行编辑器,当按下‘#’时代表按下了一次退格符,当按下‘@’时代表一个退行符(使当前行的字符全部无效)。例如,假设从终端接收了这样的两行字符: Whil#lr#e(s#*s) outcha@putchar(*s=#++) 则实际有效的是下列两行: While(*s) putchar(*s++) 请你编写一个程序,输出实际有效的字符串。 | ||||||
Input | ||||||
第一行是一个整数T,表示测试数据组数。 接下来每行为一个字符串(不含空格和任何空白),表示输入的原始字符串
| ||||||
Output | ||||||
输出最终的正确字符串。 | ||||||
Sample Input | ||||||
2 Whil#lr#e(s#*s) outcha@putchar(*s=#++)
| ||||||
Sample Output | ||||||
While(*s) putchar(*s++)
| ||||||
Source | ||||||
2016级新生程序设计全国邀请赛 |
题解:倒着搞一遍就可以了。
AC代码:
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string str,s;
int t,j;
cin>>t;
while(t--)
{
cin>>str;
j=0;
for(int i=str.length()-1; i>=0; i--)
{
if(str[i]=='@')break;
else if(str[i]=='#') i--;
else
{
s[j]=str[i];
j++;
}
}
for(int i=j-1;i>=0;i--)cout<<s[i];cout<<endl;
}
return 0;
}