#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
typedef long ElemType;
typedef struct
{
ElemType *base;
ElemType *top;
int StackSize;
}sqStack;
void InitStack(sqStack *s)
{
s->base=(ElemType *)malloc
(MAXSIZE*sizeof(ElemType));
if(!s->base)
{
exit(0);
}
s->top=s->base;
s->StackSize=MAXSIZE;
}
void Push(sqStack *s,ElemType e)
{
if(s->top-s->base>=s->StackSize)
{
exit(0);
}
*(s->top)=e;
s->top++;
}
void Pop(sqStack *s,ElemType *e)
{
if(s->top==s->base)
{
exit(0);
}
*e=*--(s->top);
}
int StackLen(sqStack s)
{
return s.top-s.base;
}
int main()
{
sqStack s;
long sum=0;
long d,e;
char c;
InitStack(&s);
scanf("%c",&c);
while(c!='@')
{
while(c>='0'&&c<='9')
{
sum=sum*10+(c-'0');
scanf("%c",&c);
}
if(c!='-'&&c!='+'&&c!='*'&&c!='/')
{
Push(&s,sum);
}
switch(c)
{
case '+':
Pop(&s,&d);
Pop(&s,&e);
Push(&s,e+d);
break;
case '-':
Pop(&s,&d);
Pop(&s,&e);
Push(&s,e-d);
break;
case '*':
Pop(&s,&d);
Pop(&s,&e);
Push(&s,e*d);
break;
case '/':
Pop(&s,&d);
Pop(&s,&e);
Push(&s,e/d);
break;
}
sum=0;
scanf("%c",&c);
}
Pop(&s,&e);
printf("%ld\n",e);
return 0;
}
标签:洛谷,sqStack,int,题解,top,long,p1449,base,ElemType
From: https://blog.csdn.net/2301_79969370/article/details/140245849