题解 | #记票统计#
记票统计
http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int num1 = in.nextInt();
in.nextLine();
String s1 = in.nextLine();
String[] c1 = s1.split(" ");
LinkedHashMap<String, Integer> lhm = new LinkedHashMap<String, Integer>();
for(int i = 0; i<num1; i++){
lhm.put(c1[i],0);
}//候选人
int num2 = in.nextInt();
in.nextLine();
String s2 = in.nextLine();
String[] c2 = s2.split(" ");
int ill =0;
for(int i = 0; i<num2; i++){
String ch = c2[i];
if( ! lhm.containsKey(ch) ){ ill++; }
else{ lhm.put( ch, lhm.get(ch)+1); }//如果包含KEY,直接放入put(key, value+1)
}//for_i
for(String key: lhm.keySet() ){
System.out.println(key+" : "+lhm.get(key));
}
System.out.println("Invalid : "+ill);
}//main
}//Main
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int num1 = in.nextInt();
in.nextLine();
String s1 = in.nextLine();
String[] c1 = s1.split(" ");
LinkedHashMap<String, Integer> lhm = new LinkedHashMap<String, Integer>();
for(int i = 0; i<num1; i++){
lhm.put(c1[i],0);
}//候选人
int num2 = in.nextInt();
in.nextLine();
String s2 = in.nextLine();
String[] c2 = s2.split(" ");
int ill =0;
for(int i = 0; i<num2; i++){
String ch = c2[i];
if( ! lhm.containsKey(ch) ){ ill++; }
else{ lhm.put( ch, lhm.get(ch)+1); }//如果包含KEY,直接放入put(key, value+1)
}//for_i
for(String key: lhm.keySet() ){
System.out.println(key+" : "+lhm.get(key));
}
System.out.println("Invalid : "+ill);
}//main
}//Main