题解 | #简单错误记录#

简单错误记录

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

这道题并不困难,耐心点,应该都能回答出来
重点在于记不记得相应的代码 
1、String[] arr = str.split("\\\\");  分割字符串
2、s = s.substring(s.length()-16);   取出字符串中的一部分
3、 if(map.containsKey(key))  map中是否包含某个元素
4、s = s.substring(s.length()-16);   取出string中的一部分
5、map.keySet()  取出map中的key



import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<String , Integer> map = new LinkedHashMap<String , Integer>();
        while(sc.hasNext()){
            String str = sc.next();
            int linenum = sc.nextInt();
            String[] arr = str.split("\\\\");
            String s = arr[arr.length-1];
            if(s.length() > 16){
                s = s.substring(s.length()-16);
            }
            String key = s + " " + linenum;
            int value = 1;
            if(map.containsKey(key)){
                map.put(key , map.get(key)+1);
            }else{
                map.put(key , value);
            }
        }
        int count = 0;
        for(String string : map.keySet()){
            count++;
            if(count > (map.keySet().size()-8)){
                System.out.println(string + " " + map.get(string));
            }
        }
    }
}
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<String , Integer> map = new LinkedHashMap<String , Integer>();
        while(sc.hasNext()){
            String str = sc.next();
            int linenum = sc.nextInt();
            String[] arr = str.split("\\\\");
            String s = arr[arr.length-1];
            if(s.length() > 16){
                s = s.substring(s.length()-16);
            }
            String key = s + " " + linenum;
            int value = 1;
            if(map.containsKey(key)){
                map.put(key , map.get(key)+1);
            }else{
                map.put(key , value);
            }
        }
        int count = 0;
        for(String string : map.keySet()){
            count++;
            if(count > (map.keySet().size()-8)){
                System.out.println(string + " " + map.get(string));
            }
        }
    }
}

全部评论

相关推荐

C9本港硕都给我挂了,好歹给个面试啊
丶西瓜:人太多,给他们惯的
投递海尔等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
09-05 11:25
点赞 评论 收藏
分享
秋招投简历提醒助手:因为实习生都跑去秋招了。不过现在实习是不是太晚了点
点赞 评论 收藏
分享
码农顶针:估计让你免费辅导老板孩子的学习
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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