PersonalCorpus 版 (精华区)

904399 2002/06/15 10:22:09.855
Big Guava ... 755 C++ Accepted 0:02.560 1788

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int sort_function( const void *a, const void *b)
{
   return memcmp(a,b,7);
}


void main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\uva\\input755.txt","r",stdin);
    freopen("c:\\uva\\output755.txt","w",stdout);
#endif

    int i,j,k,n,max,fin;
    char s[100];
    char t[100000][7];

    scanf("%d\n",&n);
    while(n>0) {
        n--;
        scanf("%d\n",&max);
        for (i=0;i<max;i++) {
            gets(s); k=0;
            for (j=0;j<7;j++) {
                while (s[k]=='-') k++;
                switch (s[k]) {
                    case 'A' : t[i][j]='2'; break;
                    case 'B' : t[i][j]='2'; break;
                    case 'C' : t[i][j]='2'; break;
                    case 'D' : t[i][j]='3'; break;
                    case 'E' : t[i][j]='3'; break;
                    case 'F' : t[i][j]='3'; break;
                    case 'G' : t[i][j]='4'; break;
                    case 'H' : t[i][j]='4'; break;
                    case 'I' : t[i][j]='4'; break;
                    case 'J' : t[i][j]='5'; break;
                    case 'K' : t[i][j]='5'; break;
                    case 'L' : t[i][j]='5'; break;
                    case 'M' : t[i][j]='6'; break;
                    case 'N' : t[i][j]='6'; break;
                    case 'O' : t[i][j]='6'; break;
                    case 'P' : t[i][j]='7'; break;
                    case 'R' : t[i][j]='7'; break;
                    case 'S' : t[i][j]='7'; break;
                    case 'T' : t[i][j]='8'; break;
                    case 'U' : t[i][j]='8'; break;
                    case 'V' : t[i][j]='8'; break;
                    case 'W' : t[i][j]='9'; break;
                    case 'X' : t[i][j]='9'; break;
                    case 'Y' : t[i][j]='9'; break;
                    default          : t[i][j]=s[k];
                }
                k++;
            }
        }
        qsort((void *)t, max, 7, sort_function);
        j=0; k=1; fin=0;
        for (i=1;i<max;i++)
            if (memcmp(t[i],t[j],7)==0) k++; else {
                if (k>1) {
                    printf("%c%c%c-%c%c%c%c %d\n",t[j][0],t[j][1],
t[j][2]
                        ,t[j][3],t[j][4],t[j][5],t[j][6],k);
                    fin=1;
                }
                j=i;k=1;
            }
        if (k>1) {
            printf("%c%c%c-%c%c%c%c %d\n",t[j][0],t[j][1],t[j][2]
                ,t[j][3],t[j][4],t[j][5],t[j][6],k);
            fin=1;
        }
        if (fin==0) printf("No duplicates.\n");
        if (n>0) printf("\n");
        gets(s);

    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.842毫秒