题解 | #简单错误记录#

简单错误记录

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<String> list = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine().trim();
            if (line.length()==0){
                break;
            }
            String[] array = line.split(" ");
            String file[] = array[0].split("\\\\");
            String fileName = file[file.length - 1];
            if (fileName.length() > 16) {
                fileName = fileName.substring(fileName.length() - 16);
            }
            String result = fileName + " " + array[1];
            if (map.containsKey(result)) {
                map.put(result, map.get(result) + 1);
            } else {
                map.put(result, 1);
                list.add(result);
            }
        }
        int start = Math.max(0,list.size()-8);
        while (start<list.size()){
            String key = list.get(start);
            System.out.println(key+" "+map.get(key));
            start++;
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务