https://www.luogu.org/problemnew/show/P1067
import java.util.Scanner;
public class Main {
private static Scanner cin;
public static void main(String args[]) throws Exception {
cin = new Scanner(System.in);
int x = cin.nextInt();
StringBuilder sb = new StringBuilder("");
int tmp;
for(int i=0;i<=x;i++) {
tmp = cin.nextInt();
if(0 != tmp) {
if(0 == (x-i)){
if(tmp>0) {
sb.append(String.format("+%d", tmp*1));
}else {
sb.append(String.format("%d", tmp*1));
}
}else if(1 == (x-i)){
if(1 == tmp) {
sb.append("+x");
}else if(-1 == tmp) {
sb.append("-x");
} else if(0 <= tmp) {
sb.append(String.format("+%dx", tmp));
}else {
sb.append(String.format("%dx", tmp));
}
}else {
if(1 == tmp) {
sb.append(String.format("+x^%d", x-i));
}else if(-1 == tmp) {
sb.append(String.format("-x^%d", x-i));
} else if(0 <= tmp) {
sb.append(String.format("+%dx^%d", tmp,x-i));
}else {
sb.append(String.format("%dx^%d", tmp,x-i));
}
}
}
}
String prefix = sb.substring(0, 1);
if(prefix.equals("+") ) {
System.out.println(sb.substring(1, sb.length()));
}else {
System.out.println(sb.toString());
}
}
}