fork(4) download
  1. //package main;
  2.  
  3. import java.util.Map;
  4. import java.util.Scanner;
  5. import java.util.TreeMap;
  6.  
  7. class Main {
  8.  
  9. public static void main(String[] args) {
  10. run();
  11. }
  12.  
  13. static void run() {
  14. Scanner in = new Scanner(System.in);
  15. int total_datasets;
  16. total_datasets = in.nextInt();
  17. in.nextLine();
  18. int i;
  19. for (i = 1; i <= total_datasets; i++) {
  20. int total_numbers_in_data;
  21. total_numbers_in_data = in.nextInt();
  22. int count = 0;
  23. Map<String, Integer> sorted_numbers = new TreeMap<>();
  24. for (int j = 1; j <= total_numbers_in_data; j++) {
  25. StringBuilder n = new StringBuilder(in.next());
  26. update_number(n);
  27. if (sorted_numbers.containsKey(n.toString())) {
  28. int v = sorted_numbers.get(n.toString()) + 1;
  29. sorted_numbers.remove(n.toString());
  30. sorted_numbers.put(n.toString(), v);
  31. count++;
  32. }
  33. else {
  34. sorted_numbers.put(n.toString(), 1);
  35. }
  36. }
  37. if (count == 0) {
  38. System.out.println("No duplicates.");
  39. }
  40. else {
  41. for (Map.Entry<String, Integer> entry : sorted_numbers.entrySet()) {
  42. if (entry.getValue() > 1) {
  43. System.out.println(entry.getKey() + " " + entry.getValue());
  44. }
  45. }
  46. }
  47.  
  48. if (i != total_datasets) {
  49. System.out.println();
  50. }
  51. }
  52. }
  53.  
  54. static void update_number(StringBuilder n) {
  55. for (int i = 0; i < n.length(); i++) {
  56. char c = n.charAt(i);
  57. if (c == '-') {
  58. n.deleteCharAt(i);
  59. --i;
  60. }
  61. else if (Character.isUpperCase(c)) {
  62. switch (c) {
  63. case 'A':
  64. case 'B':
  65. case 'C':
  66. n.replace(i, i + 1, "2");
  67. break;
  68. case 'D':
  69. case 'E':
  70. case 'F':
  71. n.replace(i, i + 1, "3");
  72. break;
  73. case 'G':
  74. case 'H':
  75. case 'I':
  76. n.replace(i, i + 1, "4");
  77. break;
  78. case 'J':
  79. case 'K':
  80. case 'L':
  81. n.replace(i, i + 1, "5");
  82. break;
  83.  
  84. case 'M':
  85. case 'N':
  86. case 'O':
  87. n.replace(i, i + 1, "6");
  88. break;
  89. case 'P':
  90. case 'R':
  91. case 'S':
  92. n.replace(i, i + 1, "7");
  93. break;
  94.  
  95. case 'T':
  96. case 'U':
  97. case 'V':
  98. n.replace(i, i + 1, "8");
  99. break;
  100. case 'W':
  101. case 'X':
  102. case 'Y':
  103. n.replace(i, i + 1, "9");
  104. break;
  105. default:
  106. break;
  107. }
  108.  
  109. }
  110. }
  111. n.insert(3, '-');
  112. }
  113. }
  114.  
Success #stdin #stdout 0.14s 321344KB
stdin
1

12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
stdout
310-1010 2
487-3279 4
888-4567 3