题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
int m = Integer.parseInt(input.nextLine());
String value = input.nextLine();
String[] strings = value.split(" ");
int n = Integer.parseInt(input.nextLine());
String tickertvalue = input.nextLine();
String[] tickertstrings = tickertvalue.split(" ");
LinkedHashMap<String, Integer> hashMap = new LinkedHashMap<>();
for (String string : strings) {
hashMap.put(string, 0);
}
int use = 0;
for (String tickertstring : tickertstrings) {
if (hashMap.containsKey(tickertstring)) {
hashMap.put(tickertstring, hashMap.get(tickertstring) + 1);
use += 1;
}
}
Set<Map.Entry<String, Integer>> entrySet = hashMap.entrySet();
for (Map.Entry<String, Integer> stringIntegerEntry : entrySet) {
System.out.println(stringIntegerEntry.getKey() + " : " +
stringIntegerEntry.getValue());
}
System.out.println("Invalid : " + (tickertstrings.length - use));
}
}
}
