ZSYhaouuan @ 2024-08-29 16:55:48
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int main(){
int n;
cin>>n;
for(int i=n;i>=0;i--){
cin>>a[i];
}
for(int i=n;i>=0;i--){
bool is=1;
if(a[i]<0){
if(abs(a[i])==1){
cout<<'-';
}else{
cout<<a[i];
}
}else if(a[i]==0){
is=0;
}else{
if(i!=n){
cout<<'+';
if(abs(a[i])!=1 || (abs(a[i])==1&&i==0)){
cout<<a[i];
}
}else{
if(abs(a[i])!=1){
cout<<a[i];
}
}
}
if(is){
if(i>=2){
cout<<'x'<<'^'<<i;
}else if(i==1){
cout<<'x';
}
}
}
return 0;
}
by LIUHAOYU2013 @ 2024-10-03 22:08:26
@ZSYhaouuan
#include <iostream>
using namespace std;
int main(){
int n,a;
scanf("%d", &n);
for(int i = n;i >= 0; -- i){
scanf("%d", &a);
if(a){
if(i != n && a > 0) printf("+");
if(abs(a) > 1 || i == 0) printf("%d", a);
if(a == -1 && i) printf("-");
if(i > 1) printf("x^%d", i);
if(i == 1) printf("x");
}
}
return 0;
}