https://open.kattis.com/problems/rollcall 该问题已在上面列出。
在while循环条件下,大约每一次scan.has ....在控制台中按下两次输入键之后,我都无法终止代码。
导入java.util。*;
公共课程点名{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> arr = new ArrayList<String>();
HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
String command = scan.nextLine();
while (!command.isEmpty()) {
String[] test = command.split(" ");
ArrayList<String> temp = new ArrayList<String>();
arr.add(test[0]);
arr.add(test[1]);
if (!(map.containsKey(test[0]))) {
temp.add(test[1]);
map.put(test[0], temp);
}
else {
temp.add(test[1]);
ArrayList<String> quick = map.get(test[0]);
temp.addAll(quick);
map.put(test[0], temp);
}
command=scan.nextLine();
}
int count = 0;
for (int i = arr.size()-1; i>=0; i-=2) {
ArrayList<String> newarr = map.get(arr.get(i-1));
if (newarr.size() == 1) System.out.println(arr.get(i-1));
else{
System.out.println(arr.get(i-1) +" " + map.get(arr.get(i-1)).get(count));
count++;
}
}
}
}