欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ACM PKU 1002 487-3279 http://acm.pku.edu.cn/JudgeOnline/problem?id=1002

程序员文章站 2022-05-21 23:30:25
...
#include <iostream>

using namespace std;

int sign[10000000];


void init(int n)
{
while (n--)
{
   char str[1024];
   cin >> str;
   int sum = 0;
   for (int i = 0 ; i < strlen(str); i++)
   {
    int temp = 0;
   
    switch (str[i])
    {
    case 'A': case 'B': case 'C': case '2':   
    
     temp = 2 ;
     sum = 10 * sum + temp ; 
     break;
    
    
    
    case 'D': case 'E': case 'F': case '3':   
    
     temp = 3 ;
     sum = 10 * sum + temp ; 
     break;
    
    case 'I': case 'G': case 'H':    case '4':
    
     temp = 4 ;
     sum = 10 * sum + temp ; 
     break;
    
    case 'J': case 'K': case 'L': case '5':
    
     temp = 5 ;
     sum = 10 * sum + temp ; 
     break;
    
    case 'O': case 'M': case 'N': case '6':
    
     temp = 6 ;
     sum = 10 * sum + temp ; 
     break;
    
    case 'P': case 'R': case 'S': case '7':    
     temp = 7 ;
     sum = 10 * sum + temp ; 
     break;
    
    case 'T': case 'U': case 'V': case '8':    
     temp = 8 ;
     sum = 10 * sum + temp ; 
     break;
    
    case 'W':     case 'X': case 'Y': case '9':
    
     temp = 9 ;
     sum = 10 * sum + temp ; 
     break;
    
    case '1':
    
     temp = 1 ;
     sum = 10 * sum + temp ; 
     break;
    
    
    case '0':
     sum = 10 * sum ; 
     break;
    
    default:
     break;
    }
   }
   sign[sum]++ ;
}
}

void ouput()
{
int count = 0;
for (int i = 0 ; i < 10000000; i++)
{
   if (sign[i] != 0 && sign[i] != 1)
   {
      int j = i;
    // cout << j/10000;
    printf ("%03d", j/10000);

   
    j = j%10000;
    //cout<<'-'; 
    //cout << j; 
    printf ("-%04d", j);
    printf (" %d\n", sign[i]);
    //cout<<' '<< sign[i]<<endl;
    count++;
   }

}
if (count == 0)
   {
    cout <<"No duplicates."<<endl;
   }
}

int main()
{
int case_n;
cin >> case_n;
memset(sign,0,sizeof(sign));
    init(case_n);
ouput();
return 0;
}

转载于:https://www.cnblogs.com/Chinese-Coder-Clarence/articles/2039237.html