京东面试题 股票委托

import java.util.*; public class Main { public static void main(String[] args) {
        Scanner cin = new Scanner(System.in); while (cin.hasNext()) {
            Map<Integer,Integer> S = new TreeMap<>(new Comparator<Integer>(){ @Override  public int compare(Integer o1, Integer o2) { return o2-o1;
                }
            });
            Map<Integer,Integer> B = new TreeMap<>(new Comparator<Integer>(){ @Override  public int compare(Integer o1, Integer o2) { return o2-o1;
                }
            }); int n = cin.nextInt(); int s = cin.nextInt(); for (int i = 0; i <n; i++) {
                String flagB = cin.next(); if (flagB.equals("B")){ int one = cin.nextInt(); int two = cin.nextInt(); if (B.containsKey(one)){
                        B.put(one,B.get(one)+two);
                    }else {
                        B.put(one,two);
                    }
                }else { int one = cin.nextInt(); int two = cin.nextInt(); if (S.containsKey(one)){
                        S.put(one,S.get(one)+two);
                    }else {
                        S.put(one,two);
                    }
                }
            } // 显示  int countS = 0;
            Iterator itS = S.keySet().iterator(); while (itS.hasNext()&&countS<s){
                Object key = itS.next();
                Object value = S.get(key);
                System.out.println("S "+key+" "+value);
                countS++;
            } int countB = 0;
            Iterator itB = B.keySet().iterator(); while (itB.hasNext()&&countB<s){
                Object key = itB.next();
                Object value = B.get(key);
                System.out.println("B "+key+" "+value);
                countB++;
            }
        }
    }
}
全部评论

相关推荐

05-26 09:07
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
墨西哥大灰狼:如果你的校友卤馆还在的话,他肯定会给你建议的,可是卤馆注销了@ 程序员卤馆
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-24 16:03
欲挽天倾:专业毫无意义的 找工作都是看学校title的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务