PAT-B-1010. 一元多项式求导(Java)

试题描述

试题代码

package com.hym.PAT_B;

import java.util.Scanner;

/**
 * Created by ymhou on 2016/11/21.
 *通过全部测试点,答案正确
 */
public class PAT_B_1010 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String numArray[] = line.split("\\s+");

        if(numArray.length==2 && numArray[1].equals("0")){
            System.out.print("0 0");
        }else {
            String outstring="";
            for(int i=0; i<numArray.length; i=i+2){
                int a = Integer.parseInt(numArray[i])*Integer.parseInt(numArray[i+1]);
                int b = Integer.parseInt(numArray[i+1])-1;
                if(a==0) continue;
                outstring = outstring+a+" "+b+" ";
            }

            System.out.print(outstring.substring(0,outstring.length()-1));
        }
    }
}

推荐阅读更多精彩内容