P1449 后缀表达式
点击查看代码
#include<bits/stdc++.h>
using namespace std;
stack<int> stk;
int main()
{
char c;
int num=0;
while(cin>>c){
if(c=='@') break;
if(c>='0'&&c<='9'){
num=num*10+(c-'0');
}
else if(c=='.'){
stk.push(num);
num=0;
}
else {
int y=stk.top();stk.pop();
int x=stk.top();stk.pop();
if(c=='+') stk.push(x+y);
else if(c=='-') stk.push(x-y);
else if(c=='*') stk.push(x*y);
else if(c=='/') stk.push(x/y);
}
}
cout<<stk.top()<<endl;
return 0;
}

浙公网安备 33010602011771号