#include <bits/stdc++.h>
using namespace std;
typedef char ElemType;
class Stack{
private:
ElemType *up;
ElemType *base;
ElemType length;
public:
Stack(){
base = new ElemType;
up = base;
length = 0;
}
void push(ElemType x){
*up++ = x;
length++;
}
void pop(){
up--;
length--;
}
ElemType top(){
return *(up - 1);
}
ElemType size(){
return length;
}
bool empty(){
return 0 == length;
}
};
int main()
{
char st[1123];
while(cin >> st)
{
Stack Q;
Stack P;
for(int i = 0; st[i]; i++)
{
if(st[i] == '#')
{
Q.pop();
}
else if(st[i] == '@')
{
while(!Q.empty())
{
Q.pop();
}
}
else
{
Q.push(st[i]);
}
}
while(!Q.empty())
{
P.push(Q.top());
Q.pop();
}
while(!P.empty())
{
cout << P.top();
P.pop();
}
cout << endl;
}
return 0;
}
基于栈与队列的行编辑器
最新推荐文章于 2020-07-29 09:28:42 发布