Hokage @ 2019-07-13 21:49:50
#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
using namespace std;
string a;
stack<int> q;
int used=0;
char zf[10]={'0','1','2','3','4','5','6','7','8','9'};
int zf1[10]={0,1,2,3,4,5,6,7,8,9};
int tot;
int zh(char h)
{
for(int i=0;i<9;i++)
{
if(h==zf[i])
return zf1[i];
}
}
int main()
{
cin>>a;
for(int i=0;i<a.size();i++)
{
if(a[i]=='.')
{
if(used==0)
continue;
q.push(used);
used=0;
continue;
}
used=zh(a[i]);
if(a[i]=='+')
{
int b=q.top();q.pop();
int c=q.top();q.pop();
q.push(b+c);
continue;
}
if(a[i]=='-')
{
int b=q.top();q.pop();
int c=q.top();q.pop();
q.push(c-b);
continue;
}
if(a[i]=='*')
{
int b=q.top();q.pop();
int c=q.top();q.pop();
q.push(b*c);
continue;
}
if(a[i]=='/')
{
int b=q.top();q.pop();
int c=q.top();q.pop();
q.push(c/b);
continue;
}
}
tot=q.top();
printf("%d\n",tot);
return 0;
}
by HZAUqzx @ 2019-07-30 19:15:30
@Hokage
dalao啊
如果输入两位数或两位以上你