Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
99466 | 刘星辰liuxingchen | 多项式输出 | C++ | 通过 | 100 | 0 MS | 248 KB | 1548 | 2023-08-22 19:49:39 |
#include<bits/stdc++.h> using namespace std; int n; int a[110]; string s; int main() { cin>>n; for(int i=1;i<=n+1;i++) { cin>>a[i]; } if(n==0) { cout<<a[1]; return 0; } if(a[1]<0) { if(a[1]==-1) { cout<<"-"; cout<<"x"; cout<<"^"; cout<<n; } else { cout<<a[1]; cout<<"x"; cout<<"^"; cout<<n; } } else if(a[1]>=1) { if(a[1]==1) { cout<<"x"; cout<<"^"; cout<<n; } else { cout<<a[1]; cout<<"x"; cout<<"^"; cout<<n; } } for(int i=2;i<=n+1;i++) { if(1==n-i+1) { if(a[i]>=1) { cout<<"+"; if(a[i]==1) { cout<<"x"; } else { cout<<a[i]; cout<<"x"; } } else if(a[i]<=-1) { if(a[i]==-1) { cout<<"-"; cout<<"x"; } else { cout<<a[i]; cout<<"x"; } } } else if(i<=n) { if(a[i]>=1) { cout<<"+"; if(a[i]==1) { cout<<"x"; cout<<"^"; cout<<n-i+1; } else { cout<<a[i]; cout<<"x"; cout<<"^"; cout<<n-i+1; } } else if(a[i]<=-1) { if(a[i]==-1) { cout<<"-"; cout<<"x"; cout<<"^"; cout<<n-i+1; } else { cout<<a[i]; cout<<"x"; cout<<"^"; cout<<n-i+1; } } } else { if(a[i]>=1) { cout<<"+"; cout<<a[i]; } else if(a[i]<=-1) { cout<<a[i]; } } } return 0; }