1002 487-3279

之前用stl::map,tle了

换sort+O(n)扫一遍ac

 

  1. //3513284_AC_1235MS_2964K
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<string>
  5. using namespace std;
  6. #define MAXN 100000
  7. int i,j,n,t;
  8. int pad[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};
  9. bool god;
  10. char buf[1000];
  11. string tel[MAXN];
  12. int main()
  13. {
  14.     //freopen("d:/in.txt","r",stdin);
  15.     while(cin>>n)
  16.     {
  17.         for(i=0;i<n;++i)
  18.         {
  19.             scanf("%s",&buf);
  20.             t=0;
  21.             tel[i].resize(7);
  22.             for(j=0;t<7&&j<strlen(buf);++j)
  23.             {
  24.                 if(buf[j]!='-')
  25.                 {
  26.                     if(buf[j]>='A'&&buf[j]<='Z')
  27.                     {
  28.                         tel[i][t++]=pad[buf[j]-'A']+48;
  29.                     }
  30.                     else
  31.                     {
  32.                         tel[i][t++]=buf[j];
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.         god=true;
  38.         sort(tel,tel+n);
  39.         for(i=0;i<n;)
  40.         {
  41.             t=1;
  42.             for(j=i+1;j<n&&tel[j]==tel[i];++j)
  43.             {
  44.                 t++;
  45.             }
  46.             if(t>1)
  47.             {
  48.                 god=false;
  49.                 printf("%c%c%c-%c%c%c%c %d/n",tel[i][0],tel[i][1],tel[i][2],
  50.                     tel[i][3],tel[i][4],tel[i][5],tel[i][6],t);
  51.             }
  52.             i=j;
  53.         }
  54.         if(god)
  55.         {
  56.             cout<<"No duplicates./n";
  57.         }
  58.     }
  59.     return 0;
  60. }

你可能感兴趣的:(c)