這是我寫的Java程式碼
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class UVa10420 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int count = cin.nextInt();
String temp1[] = new String[count];
Integer count1[] = new Integer[count];
for(int i = 0 ; i < count ; i++) {
if(cin.hasNext()) {
String country = cin.next();
temp1[i] = country;
cin.nextLine();
}else {
break;
}
}
cin.close();
Map<String,Integer> dec = new HashMap<String,Integer>();
List<String> list = new ArrayList<String>();
Collections.addAll(list, temp1);
String temp2[] = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
int c = 1;
for (int j = 0; j < list.size(); j++) {
if (list.get(i).equals(list.get(j)) && i != j) {
c++;
list.remove(j);
}
}
temp2[i] = list.get(i);
count1[i] = c;
dec.put(temp2[i], count1[i]);
}
String[] temp3 = new String[list.size()];
for(int i = 0 ; i < list.size() ; i++) {
temp3[i] = temp2[i];
}
Comparator<Object> com =Collator.getInstance();
Arrays.sort(temp3,com);
for (int i = 0; i < list.size() ; i++) {
System.out.println(temp3[i] + " " + dec.get(temp3[i]));
}
}
}
不知道為什麼會卡在Line58,求解謝謝!!