提交时间:2023-08-22 14:22:26
运行 ID: 99239
#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; for (int i = 1;i <= n + 1;i++){ int a = fr(); if (o == 0 && a != 0){ x = (a < 0); cout<<c[x]<<a; continue; } if (a == 0){ o--; continue; } else if (a == 1){ x = 0; if (i >= 2){ cout<<c[x]; } if (o == 1){ cout<<'x'; o--; continue; } cout<<"x^"<<o; } else if (a == -1){ x = 1; if (i >= 2){ cout<<c[x]; } if (o == 1){ cout<<'x'; o--; continue; } cout<<"x^"<<o; } else{ x = (a < 0); if (i >= 2){ cout<<c[x]; } if (i == 1 && a < 0){ cout<<'-'; } cout<<abs(a); if (o == 1){ cout<<'x'; continue; } cout<<"x^"<<o; } o--; } return 0; }