提交时间:2023-08-22 14:57:45
运行 ID: 99253
#include<bits/stdc++.h> //#define int long long using namespace std; namespace Fast{ inline int fr(){ register int x = 0,f = 1; static char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x < 0){ x = -x; putchar('-'); } if (x > 9){ fw(x / 10); } putchar(x % 10 + 48); } } using namespace Fast; char c[5] = {'+','-'}; signed main(){ int n = fr(),o,x = 0; o = n; if (n == 0){ int a = fr(); fw(a); return 0; } bool f = true; for (int i = n;i >= 0;i--){ int a = fr(); if (a == 0){ continue; } if (i == 0){ if (a > 0){ putchar('+'); } fw(a); break; } else if (i == 1){ if (a > 0 && n > 1){ putchar('+'); } if (a < 0 && n > 1){ putchar('-'); } if (a != 1 && a != -1){ fw(abs(a)); } cout<<'x'; continue; } if (a > 0 && i != n){ putchar('+'); } if (a < 0 && n > 1){ putchar('-'); } if (a != 1 && a != -1){ cout<<abs(a); } cout<<"x^"<<i; } return 0; }