#include
#include
#include
#define MaxSize 50
typedef int ElemType;
typedef struct {
ElemType data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack& S) {
S.top = -1;
}
int StackEmpty(SqStack& S) {
if (S.top == -1)
return 1;
else
return 0;
}
void Push(SqStack& S, ElemType e) {
if (S.top == MaxSize - 1)
return;
S.data[++S.top] = e;
}
void Pop(SqStack& S, ElemType& e) {
if (S.top == -1)
return;
e = S.data[S.top--];
}
int GetTop(SqStack& S) {
int e = S.data[S.top];
return e;
}
int compulate(int x1,char f,int x2) {
int e1 = x1;
int e2 = x2;
int res=0;
switch (f) {
case '+':
res = e1 + e2;
break;
case '-':
res = e1 - e2;
break;
case '*':
res = e1 * e2;
break;
case '/':
res = e1 / e2;
break;
}
return res;
}
int zhong(SqStack& S1,SqStack ) {
}
int qian(SqStack& S, char* s) {
int length = strlen(s);
for (int i = length-1; i >= 0; i--) {
if (s[i] >= '0' && s[i] <= '9') {
Push(S, s[i] - '0');
}
else {
int e1, e2;
Pop(S, e1);
Pop(S, e2);
printf("%d%c%d=%d\n", e1, s[i], e2, compulate(e1, s[i], e2));
Push(S, compulate(e1, s[i], e2));
}
}
char e;
e = GetTop(S);
return e;
}
int hou(SqStack &S,char *s) {
int length = strlen(s);
for (int i = 0; i<length; i++) {
if (s[i] >= '0' && s[i] <= '9') {
Push(S, s[i]-'0');
}
else {
int e1, e2;
Pop(S, e1);
Pop(S, e2);
printf("%d%c%d=%d\n", e2, s[i], e1, compulate(e2, s[i], e1));
Push(S, compulate(e2,s[i],e1));
}
}
char e;
e=GetTop(S);
return e ;
}
int main() {
char s[10];
gets_s(s);
SqStack S;
InitStack(S);
int x = qian(S,s);
printf("%d", x);
return 0;
}

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104