1010 一元多项式求导 (25分)(Java 题解)

1010 一元多项式求导 (25分)



原题链接:传送门

一、题目

在这里插入图片描述

二、解析

思路

题目读懂:输入案例中3 4 = 对应的输出为12 3。12是3*4的结果,3是4-1。

注意空格,注意“零多项式”的指数和系数都是 0,但是表示为 0 0。

ac代码

你可以用字符串保存,最后再把首位空格去掉。

import java.util.Scanner;

/**
 * 1010 一元多项式求导 (25分)
 *
 * @author ChangSheng
 * @date 2020-03-03
 */
public class P1010_一元多项式求导 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ans = "";
        while (sc.hasNext()) {
            int a = sc.nextInt(), b = sc.nextInt();
            if (b != 0) ans += (a*b)+" "+(b-1) + " ";
        }
        if ("".equals(ans)) ans += "0 0";
        System.out.println(ans.trim());
    }
}

你也可以边输入边打印。思路同上一样

import java.util.Scanner;

/**
 * 1010 一元多项式求导 (25分)
 *
 * @author ChangSheng
 * @date 2020-03-03
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean flag = false;
        while (sc.hasNext()) {
            int a = sc.nextInt(), b = sc.nextInt();
            if (b != 0) {
                if (!flag) flag = true;
                else  System.out.print(" ");
                System.out.print((a*b)+" "+(b-1));
            }
        }
        if (!flag) System.out.print("0 0");
}

其他

相关

PAT - 乙级 - 题解集

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值