poj 1002 487-3279

数据量较大 卡了好几次超时 看了别人的报告 说是可以把电话号码转成整数,大概就是这么做的。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=200000;
 6 char s[500];
 7 char key[26]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','0','7','7','8','8','8','9','9','9','0'};
 8 int number[maxn];
 9 int main()
10 {
11     int n;
12     scanf("%d",&n);
13     getchar();
14     for(int i=0;i<n;i++)
15     {
16         gets(s);
17         int len=strlen(s);
18         int tmp=0;
19         for(int j=0;j<len;j++)
20             if(s[j]=='Q'||s[j]=='Z'||s[j]=='-')
21             continue;
22             else if(s[j]>='A'&&s[j]<='Z')
23             tmp=tmp*10+(key[s[j]-'A']-'0');
24             else if(s[j]>='0'&&s[j]<='9')
25             tmp=tmp*10+(s[j]-'0');
26         number[i]=tmp;
27     }
28     sort(number,number+n);
29     int flag=0;
30     int i=0;
31     do
32     {
33         int index=i;
34         while(i<n&&number[++i]==number[index]);
35         if(i-index>1)
36         {
37             flag=1;
38             printf("%03d-%04d %d\n",number[index]/10000,number[index]%10000,i-index);
39         }
40     }while(i<n);
41     if(!flag)
42      printf("No duplicates.\n");
43     return 0;
44 }

 

posted @ 2013-08-05 20:52  sooflow  阅读(161)  评论(0编辑  收藏  举报