1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import java.util.Arrays; import java.util.Scanner; /** * UVA10420 */ public class UVA10420 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = sc.nextInt(); sc.nextLine(); String[] country = new String[times]; for (int i = 0; i < times; i++) { country[i] = sc.next(); sc.nextLine(); } Arrays.sort(country); for (int i = 0; i < country.length;) { String index = country[i]; int count = 0; for (int j = 0; j < country.length; j++) if (country[j].equals(index)) { count++; i = j + 1; } System.out.printf("%s %d\r\n", index, count); } sc.close(); } } |