You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
442 B

This file contains ambiguous Unicode characters!

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;
}