提交时间:2023-08-23 19:54:45

运行 ID: 99785

#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> using namespace std; int t, xs, f{ 1 }, cnt; int main() { cin >> t; t++; while (t--) { scanf("%d", &xs); if (xs) ++cnt; if (f) { f = 0; if (xs == 1 && t == 1) printf("x"); else if (xs == -1 && t == 1) printf("-x"); else if (xs == 1) printf("x^%d", t); else if (xs == -1) printf("-x^%d", t); else if (xs) printf("%dx^%d", xs, t); continue; } if (!xs) continue; else { if (xs > 0 && cnt >= 2) printf("+"); if (xs != 1 && xs != -1 || !t) printf("%d", xs); else if (xs == -1) printf("-"); if (t == 1) printf("x"); else if (t > 1) printf("x^%d", t); } } return 0; }