luogu P1067 多项式输出 模拟
1 #include <cstdio> 2 using namespace std; 3 int n; 4 int main() 5 { 6 scanf("%d",&n); 7 int tmp; 8 for (int i = 0;i <= n;i++) 9 { 10 scanf("%d",&tmp); 11 if (tmp == 0) 12 continue; 13 if (i != 0) 14 { 15 if (tmp > 0) 16 printf("+"); 17 else 18 printf("-"); 19 }else 20 { 21 if (tmp < 0) 22 printf("-"); 23 } 24 if (tmp < 0) 25 tmp *= -1; 26 if (tmp != 1) 27 printf("%d",tmp); 28 if (i == n && tmp == 1) 29 printf("%d",tmp); 30 if (i <= n - 2) 31 printf("x^%d",n - i); 32 else if (i == n - 1) 33 printf("x"); 34 } 35 return 0; 36 }
心之所动 且就随缘去吧