为什么输出没有最后一项

P1067 [NOIP2009 普及组] 多项式输出

![](https://cdn.luogu.com.cn/upload/image_hosting/mpmbvthi.png)
by w15998366226 @ 2022-10-24 22:18:09


```cpp cin>>n; for(int i=n;i>=1;i--){ cin>>a[i]; } ``` 因为你没读进去(有 $n+1$ 个数)
by Regain @ 2022-10-24 22:20:20


改了之后就错的更离谱了
by w15998366226 @ 2022-10-24 22:25:46


![](https://cdn.luogu.com.cn/upload/image_hosting/a6v6mmzh.png)
by w15998366226 @ 2022-10-24 22:27:29


```cpp #include<bits/stdc++.h> using namespace std; int a[1011],n; int main(){ cin>>n; for(int i=n;i>=0;i--){ cin>>a[i]; } for(int i=n;i>=0;i--){ if(a[i]==0){ continue; }else{ if(a[i]<0){ cout<<"-"; if(a[i]!=-1||i==0)cout<<abs(a[i]); }else if(i==n){ if(a[i]!=1||i==0)cout<<abs(a[i]); }else{ cout<<"+"; if(a[i]!=1||i==0)cout<<abs(a[i]); } if(i>0) { cout<<"x"; if(i!=1)cout<<"^"<<i; } } } return 0; } ```
by 李宗洁Jimmy @ 2022-10-24 22:53:13


|