文章
27
粉丝
0
获赞
127
访问
7.1k
中缀表达式计算模板
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
stack<int> data;
stack<char> op;
map<char, int> mp = {{'#', 1}, {'+', 2}, {'-', 2}, {'*', 3}, {'/', 3}};
op.push('#');
for(int i = 0; i < s.size(); i++) {
if(isdigit(s[i])) {
int j = i;
while(isdigit(s[j])) {
j++;
}
data.push(stoi(s.substr(i, j)));
i = j - 1;
&nb...
登录后发布评论
暂无评论,来抢沙发