文章
20
粉丝
412
获赞
13
访问
165.3k
#include <bits/stdc++.h>
using namespace std;
int Priority(char c) {
if(c == '#') return 0;
else if(c == '$') return 1;
else if(c == '(') return 2;
else if(c == '+' || c == '-') return 3;
else return 4;
}
double GetNumber(string s, int& index) {
double number = 0;
while(isdigit(s[index])) {
number = number * 10 + s[index] - '0';
index++;
}
return number;
}
double Calculate(double a, double b, char op) {
if(op == '+') return a+b;
else if(op == '-') return a-b;
else if(op == '*') return a*b;
else if(op == '/') return a/b;
else return 0;
}
int main() {
string s;
stack<char> oper;
stack<double> data;
int len, index = 0;
cin >> s;
s += '$';
oper.push('#');
len = s.length();
while(index < len) {
if(s[index] == ' ') index++;
else if(isdigit(s[index])) data.push(GetNumber(s, index));
e...
登录后发布评论
暂无评论,来抢沙发