q9iw @ 2024-10-17 17:26:07
Code
#include <stdio.h>
int n, a[107];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n + 1; i++) scanf("%d", a + i);
if(a[1] < 0 and a[1] != -1) printf("%dx^%d", a[1], n);
else if(a[1] < 0 and a[1] == -1) printf("-x^%d", n);
else if(a[1] > 0 and a[1] != 1) printf("%dx^%d", a[1], n);
else if(a[1] > 0 and a[1] == 1)printf("x^%d", n);
bool flag = false;
if(a[1]) flag = true;
for(int i = 2; i < n; i++)
{
if(flag)
{
if(a[i] < 0 and a[i] != -1) printf("%dx^%d", a[i], n - i + 1);
else if(a[i] < 0 and a[i] == -1) printf("-x^%d", n - i + 1);
else if(a[i] > 0 and a[i] != 1) printf("+%dx^%d", a[i], n - i + 1);
else if(a[i] > 0 and a[i] == 1)printf("+x^%d", n - i + 1);
}
else
{
if(a[i] < 0 and a[i] != -1) printf("%dx^%d", a[i], n - i + 1);
else if(a[i] < 0 and a[i] == -1) printf("-x^%d", n - i + 1);
else if(a[i] > 0 and a[i] != 1) printf("%dx^%d", a[i], n - i + 1);
else if(a[i] > 0 and a[i] == 1)printf("x^%d", n - i + 1);
}
if(a[i]) flag = true;
}
if(a[n] < 0 and a[n] != -1) printf("%dx", a[n]);
else if(a[n] == -1) printf("-x");
else if(a[n] > 0 and a[n] != 1) printf("+%dx", a[n]);
else if(a[n] == 1) printf("+x");
n++;
if(a[n] < 0) printf("%d", a[n]);
else if(a[n] > 0) printf("+%d", a[n]);
return 0;
}
by Jason514 @ 2024-10-17 17:31:58
input:
0
1
output:
1
你的 output: x^0+1
by q9iw @ 2024-10-17 17:42:14
%%%感谢大佬