标签:i++ pac ring const namespace ++ stack str names
接受用户从终端输入的数据,当用户发现刚刚键入的字符是错误的,‘#’表示前一个字符无效;‘@’表示当前行或之前的数据无效。
#include<iostream>
#include<cstring>
using namespace std;
const int MAX_LENGTH=100;
struct Stack{
char *top;
char *base;
int stacksize;
};
void InitStack(Stack &S){
S.base=new char[MAX_LENGTH];
S.top=S.base;
S.stacksize=MAX_LENGTH;
}
void Push(Stack &S,char e){
*(S.top++)=e;
}
void Pop(Stack &S,char &e){
e=*--S.top;
}
char GetTop(Stack &S){
return *(--S.top);
}
void ClearStack(Stack &S){
S.top=S.base;
}
void StackTraverse(Stack &S,Stack &t){
InitStack(t);
char e;
while(S.top>S.base){
Pop(S,e);
Push(t,e);
}
}
void PrintStack(Stack S){
char a;
while(S.top>S.base){
Pop(S,a);
cout<<a;
}
cout<<endl;
}
void LineEdit(){
char a[MAX_LENGTH];
Stack S,t;
InitStack(S);
char e;
while(cin>>a){
int len=strlen(a);
for(int i=0;i<len;i++){
if(a[i]==‘#‘)
Pop(S,e);
else if(a[i]==‘@‘)
ClearStack(S);
else
Push(S,a[i]);
}
StackTraverse(S,t);
PrintStack(t);
}
}
int main(){
LineEdit();
}
标签:i++ pac ring const namespace ++ stack str names
原文地址:http://www.cnblogs.com/-beyond/p/6081097.html