洛谷 P1067 多项式输出
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] data = new int[n+1];
for(int i = 0; i < n+1; i++) {
data[i] = scan.nextInt();
}
for(int i = 0; i < n+1; i++) {
int prime = n - i;
if(data[i] == 0) continue;
if(i != 0 && data[i] > 0) System.out.print("+");
if(Math.abs(data[i])>1 || prime == 0) System.out.print(data[i]);
if(data[i] == -1 && prime != 0) System.out.print("-");
if(prime >= 2) System.out.print("x^" + prime);
if(prime == 1) System.out.print("x");
}
System.out.println();
}
}