我给它的每个输入都有效。然后,Hackerrank(在线学习计算机语言的网站)会为其输入包含100000个名称和电话号码的内容,然后仅要求输入一个名称,并给出运行时错误。
import java.util.*;
import java.io.*;
public class Solution{
public static void main(String[] args) {
Map<String, Integer> tupac = new HashMap<String, Integer>();
Scanner scanner = new Scanner(System.in);
int limit = scanner.nextInt();
scanner.nextLine();
String line = "";
String check = "";
int phone;
for (int i = 0; i < limit; i++) {
line = scanner.next();
phone = scanner.nextInt();
tupac.put(line, phone);
scanner.nextLine();
}
for (int i = 0; i < limit; i++) {
check = scanner.nextLine();
// System.out.println(tupac.values());
// System.out.println(check+" "+tupac.keySet()); ci sta
if (tupac.containsKey(check)) {
System.out.print(check + "=");
System.out.println(tupac.get(check));
} else {
System.out.println("Not found");
}
}
}
}