#include <bits/stdc++.h>
using namespace std;
string s;
stack<char> st;
char p[110];
int cnt;
int yxj(char c) {
int d;
switch(c) {
case '(': d=0; break;
case '+':
case '-': d=1; break;
case '*':
case '/': d=2; break;
case '^': d=3; break;
}
return d;
}
int main() {
cin >> s;
int len=s.size();
for(int i=0; i<len; i++) {
if(isdigit(s[i]))
p[++cnt] = s[i];
else if(s[i]=='(') st.push(s[i]);
else if(s[i]==')') {
while(1) {
if(st.top()=='(') {
st.pop();
break;
} else {
p[++cnt] = st.top();
st.pop();
}
}
} else {
if(yxj(s[i])>yxj(st.top()))
st.push(s[i]);
else if(yxj(s[i])==yxj(st.top())) {
p[++cnt] = st.top();
st.pop();
st.push(s[i]);
} else {
while(1) {
if(yxj(st.top())<yxj(s[i])) {
st.push(s[i]);
break;
} else {
p[++cnt] = st.top();
st.pop();
}
}
}
}
}
for(int i=1; i<=cnt; i++)
cout << p[i] << ' ';
return 0;
}
我只做了第一步。但是这就RE了???求dalao帮调代码。。。