Language:Default简体中文 487-3279
Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10. Input The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters. Output Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line: Sample Input Sample Output 调了好久结果还是超时了........等日后再强些吧QAQ
|
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
class result {
String ss = "";
int b;
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = 0;
String s = sc.nextLine();
result p[] = new result[n];
for (int i = 0; i < n; ++i) {
p[i] = new result();
}
StringBuilder s1 = new StringBuilder();
ArrayList<String> a = new ArrayList<String>();
while (n-- > 0) {
s1.delete(0, s1.length());
s = sc.nextLine();
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == 'A' || s.charAt(i) == 'B' || s.charAt(i) == 'C') {
s1.append(2);
} else if (s.charAt(i) == 'D' || s.charAt(i) == 'E' || s.charAt(i) == 'F') {
s1.append(3);
} else if (s.charAt(i) == 'G' || s.charAt(i) == 'H' || s.charAt(i) == 'I') {
s1.append(4);
} else if (s.charAt(i) == 'J' || s.charAt(i) == 'K' || s.charAt(i) == 'L') {
s1.append(5);
} else if (s.charAt(i) == 'M' || s.charAt(i) == 'N' || s.charAt(i) == 'O') {
s1.append(6);
} else if (s.charAt(i) == 'P' || s.charAt(i) == 'R' || s.charAt(i) == 'S') {
s1.append(7);
} else if (s.charAt(i) == 'T' || s.charAt(i) == 'U' || s.charAt(i) == 'V') {
s1.append(8);
} else if (s.charAt(i) == 'W' || s.charAt(i) == 'X' || s.charAt(i) == 'Y') {
s1.append(9);
} else if (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
s1.append(s.charAt(i));
}
}
String s2 = s1.toString();
int ans = 1;
// Iterator<String> it = a.iterator();
for (int i = 0; i < a.size(); i++) {
if (s2.equals(a.get(i))) {
ans++;
}
}
a.add(s2);
if (ans == 1) {
p[k].ss = p[k].ss + s2;
p[k].b = ans;
k++;
} else {
for (int i = 0; i < k; i++) {
if (p[i].ss.equals(s2)) {
p[i].b = ans;
}
}
}
}
ArrayList<result> e = new ArrayList<result>();
for (int i = 0; i < k; i++) {
e.add(p[i]);
}
Collections.sort(e, new Comparator<result>() {
@Override
public int compare(result A, result B) {
return A.ss.compareTo(B.ss);
}
});
for (int i = 0; i < k; ++i)
if (e.get(i).b != 1)
System.out.println(e.get(i).ss.substring(0, 3) + "-" + e.get(i).ss.substring(3, e.get(i).ss.length())
+ " " + e.get(i).b);
}
}