This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,a,i;
cin>>n;
for(i=n; i>=0; i--) {
//倒着输入,便于下面输出x的几次方
cin>>a;
if(a) { //判定a是否为真(即不等于0)
if(i!=n&&a>0) cout<<"+"; //i!=n,第一项不用符号
if(abs(a)>1||i==0) cout<<a;//abs是绝对值函数,最后一项或不是-1或1时输出。
if(a==-1&&i) cout<<"-"; //-1省略1
if(i>1) cout<<"x^"<<i;
if(i==1) cout<<"x"; //指数为1时省略1
}
return 0;