1 条题解
-
0大金狮 (mengqingyu) LV 10 @ 2024-7-27 14:47:52
#include<bits/stdc++.h> using namespace std; int main(){ int n,a[10002],i,j,k; cin>>n; k=n; for(i=1;i<=n+1;i++){ cin>>a[i]; } if(a[1]!=0){ if(a[1]==1){ cout<<"x"<<"^"<<k; } if(a[1]==-1){ cout<<"-x"<<"^"<<k; } else if(a[1]!=0&&a[1]!=1&&a[1]!=-1){ cout<<a[1]<<"x"<<"^"<<k; } } k--; for(i=2;i<=n;i++){ if(a[i]>0&&k>1){ if(a[i]==1){ cout<<"+x"<<"^"<<k; } else{ cout<<"+"<<a[i]<<"x"<<"^"<<k; } k--; } else if(a[i]>0&&k==1){ if(a[i]==1){ cout<<"+x"; } else{ cout<<"+"<<a[i]<<"x"; } k--; } else if(a[i]<0&&k>1){ if(a[i]==-1){ cout<<"-x"<<"^"<<k; } else{ cout<<a[i]<<"x"<<"^"<<k; } k--; } else if(a[i]<0&&k==1){ if(a[i]==-1){ cout<<"-x"; } else{ cout<<a[i]<<"x"; } k--; } else{ k--; } } if(a[n+1]>0){ cout<<"+"<<a[n+1]; } else if(a[n+1]<0){ cout<<a[n+1]; } return 0; }
- 1
信息
- ID
- 703
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 6
- 已通过
- 4
- 上传者