Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 304973 | Accepted: 54523 |
Description
The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:
A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.
Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)
Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.
Input
Output
No duplicates.
Sample Input
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
Sample Output
310-1010 2 487-3279 4 888-4567 3
Source
East Central North America 1999
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class P1002 {
static Map<String, String> cdyhm=new TreeMap<String,String>();
static Map<String,Integer> cdy=new TreeMap<String,Integer>();
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
cdyhm.put("0","0");cdyhm.put("1","1");cdyhm.put("2","2");
cdyhm.put("3","3");cdyhm.put("4","4");cdyhm.put("5","5");
cdyhm.put("6","6");cdyhm.put("7","7");cdyhm.put("8","8");
cdyhm.put("9","9");
cdyhm.put("C","2");cdyhm.put("A","2");cdyhm.put("B","2");
cdyhm.put("D","3");cdyhm.put("E","3");cdyhm.put("F","3");
cdyhm.put("G","4");cdyhm.put("H","4");cdyhm.put("I","4");
cdyhm.put("J","5");cdyhm.put("K","5");cdyhm.put("L","5");
cdyhm.put("M","6");cdyhm.put("N","6");cdyhm.put("O","6");
cdyhm.put("P","7");cdyhm.put("R","7");cdyhm.put("S","7");
cdyhm.put("T","8");cdyhm.put("U","8");cdyhm.put("V","8");
cdyhm.put("W","9");cdyhm.put("X","9");cdyhm.put("Y","9");
int N=cin.nextInt();
while(N-->0) {
String str=cin.next().replaceAll("-", "").toUpperCase();
String[] ss=str.split("");
String s="";
for(int i=0;i<ss.length;i++) {
if(i==3)s+="-";
s+=cdyhm.get(ss[i]);
}
if(cdy.containsKey(s)) {
cdy.put(s, (cdy.get(s)+1));
}else {
cdy.put(s, 1);
}
}
for(String sss:cdy.keySet()) {
if(cdy.get(sss)>1)
System.out.println(sss+" "+cdy.get(sss));
}
cin.close();
}
}