XSTFH2024 @ 2024-09-17 11:36:24
#include<iostream>
#include<cstdio>
using namespace std;
int con[105];
int main(){
int n;
cin>>n;
for(int i=0;i<=n;i++){
cin>>con[i];
}
for(int i=n-1;i>0;i--){
if(con[i]!=0){
if(con[i]>0){
if(i==n-1){
printf("%dx^%d",con[n-i-1],i+1);
}
else{
printf("+%dx^%d",con[n-i-1],i+1);
}
}
else{
printf("%dx^%d",con[n-i-1],i+1);
}
}
}
if(con[n-1]!=0){
if(con[n-1]<0){
printf("%d",con[n-1]);
}
else{
printf("+%d",con[n-1]);
}
}
return 0;
}
这个为什么WA了
by LIUHAOYU2013 @ 2024-10-03 22:08:03
@XSTFH2024
#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;
}