题解 | #简单错误记录#

简单错误记录

https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] arg) {
        Scanner in = new Scanner(System.in);
        Map<Integer, MuLu> muLuMap = new HashMap<>();
        while (in.hasNext()) {
            String str = in.nextLine();
            String[] ss = str.split(" ");
            MuLu muLu = new MuLu();
            muLu.SetHang(Integer.parseInt(ss[1]));
            String[] s1 = ss[0].split("\\\\");
            StringBuilder stringBuilder = new StringBuilder();
            String s2 = s1[s1.length - 1];
            int j = 0;
            for (int i = s2.length() - 1; i >= 0; i--) {
                stringBuilder.append(s2.charAt(i));
                j++;
                if (j >= 16) break;
            }
            muLu.SetName(String.valueOf(stringBuilder.reverse()));
            muLu.SetCount(1);
            if (muLuMap.size() == 0) {
                muLuMap.put(0, muLu);
            } else {
                boolean pan = true;
                for (int i = 0; i < muLuMap.size(); i++) {
                    MuLu muLu1 = muLuMap.get(i);
                    if (muLu1.GetName().equals(muLu.GetName()) &&
                            muLu1.GetHang() == muLu.GetHang()) {
                        muLu.SetCount(muLu1.GetCount() + 1);
                        muLuMap.put(i, muLu);
                        pan = false;
                    }
                }
                if (pan) muLuMap.put(muLuMap.size(), muLu);
            }
        }
        for (int i = muLuMap.size()>8?muLuMap.size() - 8:0; i < muLuMap.size(); i++) {
            MuLu b = muLuMap.get(i);
            System.out.println(b.GetName() + " " + b.GetHang() + " " + b.GetCount());
        }
    }

    public static class MuLu {
        String name;
        int hang;
        int count;

        public void SetName(String name) {
            this.name = name;
        }
        public String GetName() {
            return name;
        }
        public void SetHang(int hang) {
            this.hang = hang;
        }
        public int GetHang() {
            return hang;
        }
        public void SetCount(int count) {
            this.count = count;
        }
        public int GetCount() {
            return count;
        }
    }
}

全部评论

相关推荐

11-27 12:36
已编辑
门头沟学院 前端工程师
Apries:这个阶段来说,很厉害很厉害了,不过写的简历确实不是很行,优势删掉吧,其他的还行
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务