文章
34
粉丝
89
获赞
3
访问
20.5k
#include<bits/stdc++.h>
using namespace std;
string str;
int GetPriority(char ch){
if(ch == '#') return 0;
else if(ch == '$') return 1;
else if(ch == '+' || ch == '-') return 2;
else return 3;
}
double Calculate(double a,double b,char ch){
if(ch == '+') return a + b;
else if(ch == '-') return a - b;
else if(ch == '*') return a * b;
else if(ch == '/') return a / b;
else return 0;
}
double GetNumber(int &i){
double ans = 0;
while(isdigit(str[i])){
ans *= 10;
ans += str[i] - '0';
i++;
}
return ans;
}
stack<char> oper;
stack<double> data;
int main() {
while(cin >> str){
str += "$";
oper.push('#');
int len = str.size();
int i = 0;
while(i < len){
if(isdigit(str[i])){
double num = GetNumber(i);
data.push(num);
}
else if(GetPriority(...
登录后发布评论
写的真好,哇哇哇,终于知道自己错哪了,感谢