码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1002 487-3279

时间:2014-12-16 06:26:00      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   ar   io   color   os   sp   for   

 

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 248809   Accepted: 44216

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. 

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. 

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



大致意思是给出一个字符串,然后根据映射规则转换为标准字符串,最后统计一下重复的电话号码各有多少个,如果没有重复的就输出‘No duplicates. ’。
这道题目还是很简单的,没有什么特殊的技巧。这里我将电话号码转换成一个7位的整数这样节约存储一些,运算处理起来也比较方便。,然后最这些整数进行排序,最后输出。

下面是代码:
 1 /***************************************************
 2  * POJ 1002 487-3279
 3  * author:樊列龙
 4  * 2014.12.16
 5  ***************************************************/
 6 
 7 #include <stdio.h>
 8 #include <stdlib.h>
 9 #include <ctype.h>
10 #include <string.h>
11 
12 /**
13  * 获取映射规则下的字符(数字)
14  *
15  */
16 int getMapNum(char ch)
17 {
18     switch(ch)
19     {
20         case A:caseB:caseC:
21             return 2;
22         case D:case E:case F:
23             return 3;
24         case G:caseH:caseI:
25             return 4;
26         case J:caseK:caseL:
27             return 5;
28         case M:caseN:caseO:
29             return 6;
30         case P:caseR:caseS:
31             return 7;
32         case T:caseU:caseV:
33             return 8;
34         case W:caseX:caseY:
35             return 9;
36     }
37 }
38 
39 int cmp(const void*a,const void*b)
40 {
41     return *(int*)a-*(int*)b;
42 }
43 
44 
45 int main()
46 {
47     int N,i,j;
48     scanf("%d\n",&N);
49     int a[200000];
50     for (i = 0; i < N; i++)
51     {
52         char s[256];
53         scanf("%s",s);
54         int len = strlen(s);
55 
56         int j=0;
57         for(j = 0; j <= len; j++)
58         {
59             char ch = s[j];
60             if (isdigit(ch))
61             {
62                 a[i]=a[i] * 10 + ch - 0;
63             }
64             else if (isalpha(ch))
65             {
66                 a[i]=a[i] * 10 + getMapNum(ch);
67             }
68         }
69     }
70 
71     qsort(a,N,sizeof(int),cmp);
72 
73 
74     i = 0, j = 0;
75     int isDuplicates = 1;
76     while (i < N - 1)
77     {
78         j = i;
79         while (a[i] == a[i+1])
80         {
81             i++;
82         }
83 
84         if (i != j)
85         {
86             printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,i-j+1);
87             isDuplicates = 0;
88         }
89         i++;
90     }
91 
92     if (isDuplicates)
93     {
94         printf("No duplicates.\n");
95     }
96     return 0;
97 }

 

 

 

 

POJ 1002 487-3279

标签:des   style   blog   ar   io   color   os   sp   for   

原文地址:http://www.cnblogs.com/csulennon/p/4166222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!