poj1002(水題)

來源:互聯網
上載者:User

標籤:des   style   blog   color   io   os   ar   strong   for   

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

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

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 }

 

poj1002(水題)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.