华为机试

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

import java.util.*;
public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String str = "";
            str = sc.nextLine();
            if(str.charAt(str.length() - 1) == '@'){
                System.out.println(str.substring(0,str.length() - 1));
            }
            else{
                HashMap<String,Integer> map = new HashMap<String,Integer>();
                String a[] = str.split("@");
                String big[] = a[0].split(",");
                String small[] = a[1].split(",");
                for(int i = 0;i < big.length;i++){
                    String big1[] = big[i].split(":");
                    int num1 = Integer.parseInt(big1[1]);
                    map.put(big1[0],num1);
                }
                for(int j = 0;j < small.length;j++){
                    String small1[] = small[j].split(":");
                    int num2 = Integer.parseInt(small1[1]);
                    if(map.get(small1[0]) <= num2){
                        map.remove(small1[0]);
                    }
                    else{
                        map.put(small1[0],map.get(small1[0]) - num2);
                    }
                }
                String res = "";
                for(String ss : map.keySet()){
                    res = res+ss+":"+map.get(ss)+",";
                }
                System.out.println(res.substring(0,res.length() - 1));
            }
        }
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值