P1067 多项式输出
作者:互联网
一道有点复杂的模拟题
#include<cstdio> using namespace std; int a[102]; int main() { int n; scanf("%d", &n); for(int i = n; i >= 0; i--) scanf("%d", &a[i]); for(int i = n; i >= 0; i--) { if(!a[i]) continue; if(i > 1) { if(a[i] < 0 && a[i] != -1) printf("%dx^%d", a[i], i); else if(a[i] > 0 && a[i] != 1) { if(i != n) printf("+"); printf("%dx^%d", a[i], i); } else if(a[i] == 1) { if(i != n) printf("+"); printf("x^%d", i); } else if(a[i] == -1) printf("-x^%d", i); } else if(i == 1) { if(a[i] == 1 && i != n) printf("+x"); else if(a[i] == -1 || i == n) printf("-x"); else if((a[i] < 0 && a[i] != -1) || i == n) printf("%dx", a[i]); else if(a[i] > 0 && i != n && a[i] != 1) printf("+%dx", a[i]); } else if(!i) { if(a[i] < 0 || i == n) printf("%d", a[i]); else if(a[i] > 0 && i != n) printf("+%d", a[i]); else if(a[i] == 0 && n == 0) printf("0"); } } return 0; }
标签:输出,dx,int,多项式,scanf,else,&&,printf,P1067 来源: https://www.cnblogs.com/njbw7782/p/10356217.html