rt,这依然是题目。
蒟蒻代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
stack<double>num;
stack<char>op;
double n;
char ch;
while(scanf("%lf",&n)&&n!=0){
num.push(n);
while(1){
ch=getchar();
if(ch=='\n'){
while(!op.empty()){
double a,b;
a=num.top();
num.pop();
b=num.top();
num.pop();
if(op.top()=='*')b*=a;
if(op.top()=='/')b/=a;
if(op.top()=='+')b+=a;
if(op.top()=='-')b-=a;
num.push(b);
op.pop();
}
printf("%.2lf\n",num.top());
num.pop();
break;
}
else{
ch=getchar();
getchar();
scanf("%lf",&n);
if(ch=='*'||ch=='/'){
while(!op.empty()&&(op.top()=='*'||op.top()=='/')){
double a,b;
a=num.top();
num.pop();
b=num.top();
num.pop();
if(op.top()=='*')b*=a;
if(op.top()=='/')b/=a;
num.push(b);
op.pop();
}
}
else{
while(!op.empty()){
double a,b;
a=num.top();
num.pop();
b=num.top();
num.pop();
if(op.top()=='*')b*=a;
if(op.top()=='/')b/=a;
if(op.top()=='+')b+=a;
if(op.top()=='-')b-=a;
num.push(b);
op.pop();
}
}
op.push(ch);
num.push(n);
}
}
}
return 0;
}
由于蒟蒻找不到与本蒟蒻思路相似的题解(要相似也看不懂),于是本蒟蒻只好再出来不要脸地来求助了。