题解 | 简单错误记录
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
ArrayList<String> sb = new ArrayList<>();
while(in.hasNext()){
String str = in.nextLine();
sb.add(str);
}
HashMap<String, Integer> map = new HashMap<>();
HashMap< Integer,String> map2 = new HashMap<>();
int count = 1;
for(int i = 0; i < sb.size(); i++){
String s=sb.get(i);
String[] strs = s.split(" ");
int n = Integer.parseInt(strs[1]);
String location;
String []names=strs[0].split("\\\\");
String name = names[names.length-1];
if(name.length()>16){
location = name.substring(name.length()-16);
}else {
location = name;
}
String address = location + " " + n;
if(!map.containsKey(address)){
map.put(address,1);
map2.put(count,address);
count++;
}else {
map.put(address,map.get(address)+1);
}
}
int times=8 ;
int start=1;
if(count>7){
start=count-8;
}
for (int i = start; i <count; i++) {
System.out.println(map2.get(i)+" "+map.get(map2.get(i)));
times--;
if(times==0){
break;
}
}
}
}#两个哈希表来解决,对输入不停的分割处理,写的比较粗糙
OPPO公司福利 1082人发布