救人
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];
}
全部评论 66
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#include<bits/stdc++.h> using namespace std; const int N=1e6+10; int a[N]{}; int dp[N]{}; vector<int>t[N]; void dfs(int u,int fa){ dp[u]=a[u]; for(auto son:t[u]){ if(son==fa)continue; dfs(son,u); if(dp[son]>0){ dp[u]=dp[son]+dp[u]; } } return; } int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<n;i++){ int u,v; cin>>u>>v; t[u].push_back(v); t[v].push_back(u); } dfs(1,0); int ans=-0; for(int i=0;i<=n;i++)ans=max(ans,dp[i]); cout<<ans; return 0; }
2025-05-24 来自 浙江
1#include <bits/stdc++.h> using namespace std; long long dp[2009]; struct node{ int w,c; }; vector<node> ve[100009]; int m,n,t; int main(){ cin >> m >> n; for(int i = 0;i <= n;i++){ int w,c,p; cin >> w >> c >> p; ve[p].push_back({w,c}); } for(int i = 1;i <= 100;i++){ for(int j = m;j >=0;j--){ for(int k = 0;k < ve[i].size();k++){ if(j >= ve[i][k].w) dp[j] = max(dp[j],dp[j - ve[i][k].w] + ve[i][k].c); } } } cout << dp[m]; }
2025-05-17 来自 浙江
1本贴超过榜10了!!!!!
2025-04-12 来自 浙江
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 来自 浙江
1考古(
4天前 来自 重庆
0数学专题
#include<bits/stdc++.h> using namespace std; const int N = 110; const double eps = 1e-8; double a[N][N]; int n; int gauss() { int c = 0, r = 0; for (; c < n; c++) { int t = r; for (int i = r; i < n; i++) { if (fabs(a[i][c]) > fabs(a[t][c])) { t = i; } } if (fabs(a[t][c]) < eps) continue; for (int i = c; i <= n; i++) { swap(a[t][i], a[r][i]); } for (int i = n; i >= c; i--) { a[r][i] /= a[r][c]; } for (int i = r + 1; i < n; i++) { if (fabs(a[i][c]) > eps) { for (int j = n; j >= c; j--) { a[i][j] -= a[r][j] * a[i][c]; } } } r++; } if (r < n) { for (int i = r; i < n; i++) { if (fabs(a[i][n]) > eps) { return 2; } } return 1; } for (int i = n - 1; i >= 0; i--) { for (int j = i + 1; j < n; j++) { a[i][n] -= a[i][j] * a[j][n]; } } return 0; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n + 1; j++) { scanf("%lf", &a[i][j]); } } int t = gauss(); if (t == 0) { for (int i = 0; i < n; i++) { printf("%.2lf\n", fabs(a[i][n]) < eps ? 0.00 : a[i][n]); } } else if (t == 1) { cout << "Infinite group solutions"; } else { cout << "No solution"; } return 0; }
4天前 来自 浙江
0
有帮助,赞一个