PKU OJ 1002 487-3279

PKU OJ 1002 487-3279

 

487-3279

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

Source

East Central North America 1999

 

(1)其实我的思路没啥错的,将输入的字符串转换为整数int,存在数组中,因为号码之后七位数所以这样考虑是对的,而且之后看到别人的答案大部分都觉得字符串排序处理起来比较慢;

(2)在排序这块想到的是用比较快的排序来算,从网上摘抄了一段快速排序的源码来用,结果还是超时了,于是用C++里面自带的一个qsort来排序,还写了一个比较函数;

(3)之前有个错误一直没有发现,导致多次提交心里很是蛋疼,你说做OJ这种东西,明明感觉是到处都对,感觉练到手就好了,但是还是希望最后能够AC的。一次次提交失败让我很是不爽啊;心一横去网上找测试数据;居然找到了;

(4)找到了然后又要把数据一个个读出来,又是一番百度;

(5)结果通过对比测试的数据,发现数字和大写字母的对应搞错了一个,结果改了一个符号就AC,唉;

(5)OJ还学会了不少新词呢,什么WARE还有AC的,当然大家是都想要AC的啦;

(6)很多人呢这题也没有通过,然后就是贴代码,我也想贴啊,让人绑我看看那儿错了,但是大牛们谁会帮你看代码呢,有病还是自己治,这里捅捅,那里捅捅说不定就成了呢;

(7)主要是为了学C++,各种强行面向对象,有啥高级货都拿来试试,关键是还没学到STL和更高级的东东,有所限制。

 

  1 #include 
  2 
  3 #include 
  4 
  5 using namespace std;
  6 
  7  
  8 
  9 class Phone {
 10 
 11     int table[100100];
 12 
 13     int total;
 14 
 15     int collect[100100];
 16 
 17     int flag;
 18 
 19 public:
 20 
 21     Phone(int T) {
 22 
 23         total = T;
 24 
 25         for(int i=0; i//将表初始化
 26 
 27             table[i]=0;
 28 
 29     }
 30 
 31     void TurnOver(char* s,int n) {
 32 
 33         int p=0, pow=1000000,flag=0,m;
 34 
 35         for(int i=0; i<40; i++)
 36 
 37         {
 38 
 39             if(flag >= 7)
 40 
 41                 break;
 42 
 43             switch (s[i]) {
 44 
 45                 case '0': {m=0;p=1;break;}
 46 
 47                 case '1': {m=1;p=1;break;}
 48 
 49                 case '2': case 'A': case 'B': case 'C': {m=2;p=1;break;}
 50 
 51                 case '3': case 'D': case 'E': case 'F': {m=3;p=1;break;}
 52 
 53                 case '4': case 'G': case 'H': case 'I': {m=4;p=1;break;}
 54 
 55                 case '5': case 'J': case 'K': case 'L': {m=5;p=1;break;}
 56 
 57                 case '6': case 'M': case 'N': case 'O': {m=6;p=1;break;}
 58 
 59                 case '7': case 'P': case 'R': case 'S': {m=7;p=1;break;}
 60 
 61                 case '8': case 'T': case 'U': case 'V': {m=8;p=1;break;}
 62 
 63                 case '9': case 'X': case 'Y': case 'W': {m=9;p=1;break;}
 64 
 65             }
 66 
 67             if(p==1) {
 68 
 69                 flag++;
 70 
 71                 table[n] += m*pow;
 72 
 73                 pow /= 10;
 74 
 75                 p=0;
 76 
 77             }
 78 
 79         }
 80 
 81     }
 82 
 83     void printPhone() {
 84 
 85         int a;
 86 
 87         int pow;
 88 
 89         int temp;
 90 
 91         if(flag==0) {
 92 
 93             cout << "No duplicates." << endl;
 94 
 95             return;
 96 
 97         }
 98 
 99         for(int i=0; i) {
100 
101             if(collect[i]>=1) {
102 
103                 temp = table[i];
104 
105                 //这里输出电话号码时,注意不能动table
106 
107                 pow = 1000000;
108 
109                 for(int j=0; j<7; j++) {
110 
111                     a = temp/pow;
112 
113                     temp = temp - a*pow;
114 
115                     pow = pow/10;
116 
117                     cout << a;
118 
119                     if(j==2)
120 
121                         cout << "-";
122 
123                 }
124 
125                 cout << " " << collect[i]+1 << endl;
126 
127             }
128 
129         }
130 
131     }
132 
133     
134 
135     void quickSort(int s[], int l, int r) {
136 
137         if(l<r) {
138 
139             int i=l, j=r, x=s[l];
140 
141             while (i<j) {
142 
143                 while(i=x)
144 
145                     j--;
146 
147                 if(i<j)
148 
149                     s[i++] = s[j];
150 
151                 while(ix)
152 
153                     i++;
154 
155                 if(i<j)
156 
157                     s[j--] = s[i];
158 
159             }
160 
161             s[i]=x;
162 
163             quickSort(s, l, i-1);
164 
165             quickSort(s, i+1, r);            
166 
167         }
168 
169     }
170 
171     void Sort() {
172 
173         quickSort(table,0,total-1);
174 
175     }
176 
177     void dupSelect() {
178 
179         int tmp = table[0],pos=0;
180 
181         flag=0;
182 
183         for(int i=0; i)
184 
185             collect[i]=0;
186 
187         for(int i=1; i) {
188 
189             if (tmp == table[i]) {
190 
191                     collect[pos]++;
192 
193                     flag=1;
194 
195             }
196 
197             else {
198 
199                 tmp = table[i];
200 
201                 pos=i;
202 
203             }
204 
205         }
206 
207     }    
208 
209 };
210 
211  
212 
213 int main(void) {
214 
215     int T;
216 
217     char s[40];
218 
219     cin >> T;
220 
221     getchar();
222 
223     Phone a(T);
224 
225     for(int i=0; i) {
226 
227         gets(s);
228 
229         a.TurnOver(s, i);
230 
231     }
232 
233     a.Sort();
234 
235     a.dupSelect();
236 
237     a.printPhone();
238 
239 }

 

你可能感兴趣的:(PKU OJ 1002 487-3279)