救人
2024-12-14 14:29:29
发布于:浙江
#include <bits/stdc++.h>
using namespace std;
const int maxSize = 109;
int getPriority(char op){
if(op == '+' || op == '-') return 0;
return 1;
}
void infixToPostFix(char infix[],char s2[],int& top2){
char s1[maxSize];int top1 = -1;
int i = 0;
while(infix[i] != '\0'){
if('a' <= infix[i] && infix[i] <= 'z'){
s2[++top2] = infix[i];
++i;
}
else if(infix[i] == '('){
s1[++top1] = '(';
++i;
}
else if(infix[i] == '+' || infix[i] == '-' || infix[i] == '*' || infix[i] == '/'){
if(top1 == -1 || s1[top1] == '(' || getPriority(infix[i]) > getPriority(s1[top1])){
s1[++top1] = infix[i];
++i;
}
else s2[++top2] = s1[top1--];
}
else if(infix[i] == ')'){
while(s1[top1] != '(') s2[++top2]= s1[top1--];
--top1;
++i;
}
}
while(top1 != -1) s2[++top2] = s1[top1--];
}
char s[109],res[109];
int main(){
cin >> s;
int len = -1;
infixToPostFix(s,res,len);
for(int i = 0;i <= len;i++) cout << res[i];
}
全部评论 52
d
2025-02-22 来自 浙江
3顶
2025-02-22 来自 浙江
32025-02-22 来自 浙江
3
顶
2024-12-14 来自 浙江
3顶
2024-12-14 来自 浙江
3顶
2024-12-14 来自 浙江
3@qi qpzc
2025-02-22 来自 浙江
2顶
2024-12-14 来自 浙江
2本贴超过榜10了!!!!!
1小时前 来自 浙江
13.15大根堆
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin >> n >> m; priority_queue<int> q; for(int i = 0;i < n;i++){ int a,b,c; cin >> a >> b >> c; for(int j = 1;j <= m;j++){ int tem = a * j * j + b * j + c; if(q.size() < m) q.push(tem); else if(q.top() > tem){ q.pop(); q.push(tem); } else break; } } vector<int> ve; while(q.size()){ ve.push_back(q.top()); q.pop(); } for(int i = ve.size() - 1;i >= 0;i--) cout << ve[i] << ' '; }
2025-03-15 来自 浙江
1兄弟们,顶!
2025-03-08 来自 浙江
1顶
2025-02-22 来自 浙江
1fd
2025-02-22 来自 浙江
1d
2025-02-22 来自 浙江
1d
2025-02-22 来自 浙江
1d
2025-02-22 来自 浙江
1d
2025-02-22 来自 浙江
1d
1小时前 来自 浙江
0d
1小时前 来自 浙江
0d
1小时前 来自 浙江
0qqwaseeff
1小时前 来自 浙江
0
有帮助,赞一个