import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // 读取多项式次数 int n = scanner.nextInt(); // 读取系数,顺序是a_n, a_{n-1}, ..., a_0 int[] coefficients = new int[n + 1]; for (int i = 0; i <= n; i++) { coefficients[i] = scanner.nextInt(); } scanner.close(); // 构建多项式字符串 StringBuilder result = new StringBuilder(); boolean isFirstTerm = true; // 从高次到低次处理每一项 for (int i = 0; i <= n; i++) { int coefficient = coefficients[i]; int degree = n - i; // 当前项的次数 // 系数为0的项完全省略 if (coefficient == 0) { continue; } // 处理符号 if (isFirstTerm) { // 首项若系数为正,不输出前导"+" if (coefficient < 0) { result.append("-"); } isFirstTerm = false; } else { // 后续正系数项前需加"+",负系数项加"-" if (coefficient > 0) { result.append("+"); } else { result.append("-"); } } // 处理系数的绝对值 int absCoeff = Math.abs(coefficient); // 当系数为1或-1且次数≥1时,省略系数的绝对值1 if (!(absCoeff == 1 && degree >= 1)) { result.append(absCoeff); } // 处理变量部分 if (degree > 0) { result.append("x"); // 次数为1输出"x";次数≥2输出"x^k" if (degree > 1) { result.append("^").append(degree); } } // 次数为0仅输出常数,这里不需要额外处理 } System.out.println(result.toString()); } }