Under my umbrella.

SKII

Less is more.

洛谷 P1067 多项式输出 (C/C++)

洛谷 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();
    }
}
posted @ 2020-01-14 20:57  NLYang  阅读(283)  评论(0编辑  收藏  举报