题解 | #简单错误记录#
简单错误记录
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; } } }