题解 | #简单错误记录#

简单错误记录

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

import java.util.*;

public class Main {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Map<String,Integer> map = new LinkedHashMap<>();
    while (sc.hasNext()){
        String msg = sc.nextLine();
        String[] s = msg.split(" ");
        String[] split = s[0].split("\\\\");
        String fileName = split[split.length-1];
        String realName;
        if (fileName.length()>=16){
        realName = fileName.substring(fileName.length()-16)+" "+s[1];
        }else{
            realName = fileName+" "+s[1];
        }
        if (map.containsKey(realName)){
            map.put(realName,map.get(realName)+1);
        }else{
            map.put(realName,1);
        }
    }
        Set<String> strings = map.keySet();
    if(map.size()<=8){
        for (String s : strings) {
            System.out.println(s+" "+map.get(s));
        }
    }else{
        List<String> list = new ArrayList<>(strings);
        for (int i = list.size()-8;i < list.size();i++){
            System.out.println(list.get(i) + " " + map.get(list.get(i)));
        }
    }
}

}

全部评论

相关推荐

昨天 13:48
门头沟学院 C++
点赞 评论 收藏
分享
06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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