LanderX @ 2018-07-05 21:56:10
#include<cstdio>
#include<stack>
using namespace std;
stack<int> expp;
char inpt;
int temp;
int x1, y1;
int main(){
//freopen("i.txt","r",stdin);
while(inpt = getchar() != '@'){
if(inpt >= '0' && inpt <= '9'){
temp = temp * 10 + (inpt-'0');
continue;
}else if(inpt == '.'){
expp.push(temp);
temp = 0;
continue;
}else { // 3.5.2.-*7.+@
x1 = expp.top(); expp.pop();
y1 = expp.top(); expp.pop();
switch(inpt){
case '+':
expp.push(y1 + x1);
break;
case '-':
expp.push(y1 - x1);
break;
case '*':
expp.push(y1 * x1);
break;
case '/':
expp.push(y1 / x1);
break;
}
}
}
int ans = expp.top();
printf("%d", ans);
return 0;
}
by scallop @ 2018-07-05 22:25:00
不判栈是否为空不RE才怪
by LanderX @ 2018-07-05 22:39:48
@scallop 请问栈为什么会为空呢?
by scallop @ 2018-07-05 22:52:54
@LanderX 你在每一个top()前判断!empty()
如果不RE了你就不要问了 。
by LanderX @ 2018-07-05 22:57:58
我发现问题了,是应该写成
while((inpt = getchar()) != '@')
应该加上括号的,就AC了 感谢您的关心!!
by LanderX @ 2018-07-05 22:58:06
@scallop