Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 184397 | Accepted: 31752 |
Description
电话号码的标准格式是七位十进制数,并在第三、第四位数字之间有一个连接符。电话拨号盘提供了从字母到数字的映射,映射关系如下:
A, B, 和C 映射到 2
D, E, 和F 映射到 3
G, H, 和I 映射到 4
J, K, 和L 映射到 5
M, N, 和O 映射到 6
P, R, 和S 映射到 7
T, U, 和V 映射到 8
W, X, 和Y 映射到 9
Q和Z没有映射到任何数字,连字符不需要拨号,可以任意添加和删除。 TUT-GLOP的标准格式是888-4567,310-GINO的标准格式是310-4466,3-10-10-10的标准格式是310-1010。
如果两个号码有相同的标准格式,那么他们就是等同的(相同的拨号)
你的公司正在为本地的公司编写一个电话号码薄。作为质量控制的一部分,你想要检查是否有两个和多个公司拥有相同的电话号码。
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
java 代码如下:
import java.util.Arrays; import java.util.Scanner;
public class Main {
public static void main(String args[]) { Scanner in = new Scanner(System.in); boolean noduplicate = true;
int t = in.nextInt(); String[] standard = new String[t]; int index = 0; while (t-- > 0) { String tel = in.next(); standard[index++] = standardize(tel);
} Arrays.sort(standard);
int cnt = 1; int size=standard.length; for (int i = 1; i <size ; i++) { if (standard[i].equals(standard[i - 1])) { cnt++; if(i==size-1 &&cnt!=1){ System.out.println(standard[i - 1] + " " + cnt); noduplicate = false; cnt=1; }
} else if (cnt != 1) { noduplicate = false; System.out.println(standard[i - 1] + " " + cnt); cnt = 1;
} }
if (noduplicate) { System.out.println("No duplicates."); }
}
private static String standardize(String tel) { String[] cnt = tel.split("-"); StringBuffer s = new StringBuffer(); for (int i = 0; i < cnt.length; i++) { s.append(cnt[i]); } for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == 'A' || c == 'B' || c == 'C') { s.setCharAt(i, '2');
} else if (c == 'D' || c == 'E' || c == 'F') { s.setCharAt(i, '3');
} else if (c == 'G' || c == 'H' || c == 'I') { s.setCharAt(i, '4');
} else if (c == 'J' || c == 'K' || c == 'L') { s.setCharAt(i, '5');
} else if (c == 'M' || c == 'N' || c == 'O') { s.setCharAt(i, '6');
} else if (c == 'P' || c == 'R' || c == 'S') { s.setCharAt(i, '7');
} else if (c == 'T' || c == 'U' || c == 'V') { s.setCharAt(i, '8');
} else if (c == 'X' || c == 'Y' || c == 'W') { s.setCharAt(i, '9');
}
} s.insert(3, '-');
return new String(s); }
}