poj1002(水题)

1.题目描述

                                                                                                        487-3279

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 244177   Accepted: 43308

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

2.题目大意

  输入n行字符,把每行改成相应的电话号码,输入为大写字母(除了“Q”和“Z”外)、数字有效,其他无效,然后输出重复的电话号码和重复的次数(>=2);

  输出格式为xxx-xxxx x(次数)

3.解决方法

  多种数据结构可以做,我这里用最简单的数组,一个记录出现次数,一个记录次数大于2的号码,然后输出。

4.代码

 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int judge(char c)
 9 {
10     if (((c>='0')&&(c<='9'))||((c>='A')&&(c<'Z')&&c!='Q'))
11         return 1;
12      return 0;
13 }
14 int a[10000000],b[10000000];
15 int make (char c)
16 {
17     if ((c>='0')&&(c<='9')){
18         return (int)(c-'0');
19     }
20     if ((c>='A')&&(c<='O')){
21         return ((int)(c-'A')/3+2);
22     }
23     if (c<='S')return 7;
24     if (c<='V')return 8;
25     if (c<='Y')return 9;
26 }
27 int main()
28 {
29     int n,i,d,t,k=0,sum,len;
30     char s[10000];
31     scanf("%d",&n);
32     memset(a,0,sizeof(a));
33     for (i=1;i<=n;i++){
34         scanf("%s",&s);
35         d=0;
36         t=0;
37         len=strlen(s);
38         sum=0;
39         while (t<=7&&d<len){
40             if (judge(s[d])){
41                 t++;
42                 sum=sum*10+make(s[d]);
43             }
44             d++;
45         }
46         a[sum]++;
47         if (a[sum]==2){
48             b[k]=sum;
49             k++;
50         }
51     }
52     sort(b,b+k);
53     if (k==0)printf("No duplicates.\n");
54     for (i=0;i<k;i++){
55         printf("%03d-%04d %d\n",b[i]/10000,b[i]%10000,a[b[i]]);
56     }
57     return 0;
58 }

 

posted on 2014-09-18 02:45  Only to be no.1  阅读(167)  评论(0编辑  收藏  举报

导航