package com.promise.pat; import java.util.*; public class P1002_2 { public static void main(String[]args){ // 使用Map // Key : 指数 // value: 系数 Scanner input = new Scanner(System.in); String line1 = input.nextLine(); String line2 = input.nextLine(); int n1 = Integer.parseInt(line1.split(" ")[0]); int n2 = Integer.parseInt(line2.split(" ")[0]); HashMap<Integer,Double> ploy1 = getData(line1,n1); HashMap<Integer,Double> ploy2 = getData(line2,n2); for (Map.Entry<Integer, Double> entry : ploy2.entrySet()) { Integer e = entry.getKey(); Double c = entry.getValue(); // ploy1中有 ploy2的key if(ploy1.containsKey(e)){ Double res = c.doubleValue() + ploy1.get(e).doubleValue(); if(res.doubleValue() == 0){ ploy1.remove(e);
PAT 甲级 1002 多项式相加(测试点2 一直不能通过)
最新推荐文章于 2021-09-27 17:13:04 发布