洛谷 P1067 多项式输出
作者:互联网
洛谷 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();
}
}
标签:prime,洛谷,int,多项式,System,print,out,data,P1067 来源: https://www.cnblogs.com/fromneptune/p/12194051.html