poj1002-487-3279

http://poj.org/problem?id=1002

487-3279
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 288073   Accepted: 51697

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

 

注意:如果算法里采用转化成整数比较比对,注意最后输出时,数字长度可能小于7的情况。

代码:

  1 #include <cstdio>
  2 #include <map>
  3 
  4 int StrToNum (const char *t, int len);
  5 
  6 int main ()
  7 {
  8     int count, tmp32;
  9     scanf("%d", &count);
 10     getchar();
 11 
 12     std::map<int, int> stlm;
 13     std::map<int, int>::iterator it;
 14 
 15     char c[20];
 16     int clen;
 17 
 18     for (int i = 0; i < count; i++)
 19     {
 20         for (clen = 0; ; clen++)
 21         {
 22             while (scanf("%c", &c[clen]), c[clen] == '-')
 23             {
 24             }
 25 
 26             if (c[clen] == '\n')
 27             {
 28                 break;
 29             }
 30         }
 31 
 32         tmp32 = StrToNum(c, clen);
 33         it = stlm.find(tmp32);
 34         if (it == stlm.end())
 35         {
 36             stlm[tmp32] = 1;
 37         }
 38         else
 39         {
 40             stlm[tmp32]++;
 41         }
 42     }
 43 
 44     bool bret = false;
 45     for (it = stlm.begin(); it != stlm.end(); it++)
 46     {
 47         if (it->second > 1)
 48         {
 49             bret = true;
 50             printf("%03d-%04d %d\n", (it->first) / 10000, (it->first) % 10000, it->second);
 51         }
 52     }
 53 
 54     if (!bret)
 55     {
 56         puts("No duplicates.");
 57     }
 58 
 59     return 0;
 60 }
 61 
 62 int StrToNum (const char *t, int len)
 63 {
 64     int j = 0, v = 0;
 65 
 66     for (int i = 0; ; i++)
 67     {
 68         switch (t[i])
 69         {
 70         case 'A':
 71             v += 2;
 72             break;
 73         case 'B':
 74             v += 2;
 75             break;
 76         case 'C':
 77             v += 2;
 78             break;
 79         case 'D':
 80             v += 3;
 81             break;
 82         case 'E':
 83             v += 3;
 84             break;
 85         case 'F':
 86             v += 3;
 87             break;
 88         case 'G':
 89             v += 4;
 90             break;
 91         case 'H':
 92             v += 4;
 93             break;
 94         case 'I':
 95             v += 4;
 96             break;
 97         case 'J':
 98             v += 5;
 99             break;
100         case 'K':
101             v += 5;
102             break;
103         case 'L':
104             v += 5;
105             break;
106         case 'M':
107             v += 6;
108             break;
109         case 'N':
110             v += 6;
111             break;
112         case 'O':
113             v += 6;
114             break;
115         case 'P':
116             v += 7;
117             break;
118         case 'R':
119             v += 7;
120             break;
121         case 'S':
122             v += 7;
123             break;
124         case 'T':
125             v += 8;
126             break;
127         case 'U':
128             v += 8;
129             break;
130         case 'V':
131             v += 8;
132             break;
133         case 'W':
134             v += 9;
135             break;
136         case 'X':
137             v += 9;
138             break;
139         case 'Y':
140             v += 9;
141             break;
142         default:
143             v += t[i] - '0';
144         }
145 
146         if (i + 1 < len)
147         {
148             v *= 10;
149         }
150         else
151         {
152             break;
153         }
154     }
155 
156     return v;
157 }

 

posted @ 2017-03-17 22:10  jiu~  阅读(299)  评论(0编辑  收藏  举报