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