北大 ACM 1002 题 487-3279 的 菜鸟JAVA解
来源:互联网 发布:淘宝密令红包不中 编辑:程序博客网 时间:2024/05/22 04:35
487-3279
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 196499 Accepted: 34264
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.
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.
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
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:
No duplicates.
No duplicates.
Sample Input
124873279ITS-EASY888-45673-10-10-10888-GLOPTUT-GLOP967-11-11310-GINOF101010888-1200-4-8-7-3-2-7-9-487-3279
Sample Output
310-1010 2487-3279 4888-4567 3
一定要记住没有重复数据的时候打印“No duplicates. ”,这种写法会用很多时间和空间。不过好歹弄出来了。
import java.util.*;public class Main {public static void main(String args[]) {Map map = new HashMap<String, Integer>();Scanner scanner = new Scanner(System.in);int a = scanner.nextInt();for (int i = 0; i < a; i++) {String tempString = scanner.next();tempString = process(tempString);String tempString1 = tempString.substring(0, 3);String tempString2 = tempString.substring(3, tempString.length());tempString = tempString1 + "-" + tempString2;if (map.containsKey(tempString)) {Object object = map.get(tempString);int ivalue = Integer.parseInt(object.toString());ivalue += 1;map.remove(tempString);map.put(tempString, Integer.parseInt(ivalue + ""));} else {map.put(tempString, Integer.parseInt("1"));}}Iterator it = map.entrySet().iterator();List list = new ArrayList<String>();int pp = 0;while (it.hasNext()) {Map.Entry entry = (Map.Entry) it.next();Object key = entry.getKey();Object value = entry.getValue();int p = Integer.parseInt(value.toString());if (p > 1) {list.add(key + " " + value);}}Collections.sort(list);if (list.size() == 0) {System.out.println("No duplicates.");} else {for (int l = 0; l < list.size(); l++) {System.out.println(list.get(l));}}}public static String process(String abc) {String tempString = "";for (int i = 0; i < abc.length(); i++) {char te = abc.charAt(i);char comp = '0';char comp1 = '9';if ((te >= comp) && (te <= comp1)) {tempString = tempString + te;} else if ((te >= 'A') && (te < 'Q')) {int tempInt = te - 'A';tempInt = tempInt / 3 + 2;tempString = tempString + tempInt;} else if ((te > 'Q') && (te < 'Z')) {int tempInt = te - 'A' + 2;tempInt = tempInt / 3 + 1;tempString = tempString + tempInt;}}return tempString;}}
- 北大 ACM 1002 题 487-3279 的 菜鸟JAVA解
- 北大 ACM 1002 487-3279
- ACM-北大1002 487-3279
- 北大ACM poj1002 487-3279
- 值得做的北大ACM题
- ACM北大的第1001题
- 北大ACM试题1002
- 北大ACM题分类
- 北大 ACM 1111题
- 北大ACM题分类
- 北大ACM题分类
- 北大ACM题分类
- 北大ACM题分类
- poj 1007 北大ACM java
- 【宿舍菜鸟们的ACM解题笔记】487-3279
- POJ --北大ACM题分类
- 北大ACM 做题顺序
- 【疑惑】关于北大ACM poj 1002号题目的思考
- Java线程(十):CyclicBarrier-用路障实现分阶段线程并发
- VS2008下MFC添加Web引用灰色解决办法
- 以考带学编译原理
- Java路径问题最终解决方案—可定位所有资源的相对路径寻址 .
- 命令行下的android工程的创建、编译与打包
- 北大 ACM 1002 题 487-3279 的 菜鸟JAVA解
- shell awk专题笔记
- cocos2d-x 2.0.2 创建动画的方式(根据png/swf)
- Centos上搭建能用于ok6410开发板的tftp服务器
- url地址编码与解码
- 如何保证数据库完整性
- CXF 入门步骤 详解:HelloWorld接口发布
- 学习PHP遇到的乱码问题
- sharepoint 2007 Force SharePoint Document Unlocked / Checked In