UVa - 755 487--3279

//C++ 5.3.0 - GNU C++ Compiler with options: -lm -lcrypt -O2 -pipe -DONLINE_JUDGE
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

#define mmset(X) memset(X,0,sizeof(X))

unsigned int a[10000000];
bool flags[10000000];
bool dupes[10000000];
bool noDupes;

unsigned int map[200];

unsigned long idx,iA;
unsigned long cases;
int cPhn,lPhn,lParsed,iParsed,iPhn,tmpInd,mappedInd,iTmp;
char phn[1000],buffer[10];
char parsed[1000];





int main(){


    for(iTmp=0;iTmp<=9;iTmp++) map[iTmp]=iTmp;


    map[17]=2;map[18]=2;map[19]=2;
    map[20]=3;map[21]=3;map[22]=3;
    map[23]=4;map[24]=4;map[25]=4;
    map[26]=5;map[27]=5;map[28]=5;
    map[29]=6;map[30]=6;map[31]=6;
    map[32]=7;map[34]=7;map[35]=7;
    map[36]=8;map[37]=8;map[38]=8;
    map[39]=9;map[40]=9;map[41]=9;

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);   


    scanf("%lu",&cases);

    while(cases--){

        noDupes=true;
        memset(a, 0, sizeof(a));
        memset(flags, false, sizeof(flags));
        memset(dupes, false, sizeof(dupes));


        scanf("%d",&cPhn);

        while(cPhn--){
            scanf("%s",phn);
            lPhn=strlen(phn);
            iParsed=0;

            for(iPhn=0;iPhn<lPhn;iPhn++){
                if(phn[iPhn] != '-'){
                    parsed[iParsed++]=phn[iPhn];

                }

            }
            parsed[iParsed]='\0';
            lParsed=strlen(parsed);


            idx=0;

            for(iParsed=0;iParsed<lParsed;iParsed++){

                tmpInd=parsed[iParsed]-'0';

                mappedInd=map[tmpInd];
                idx=10*idx;
                idx=idx+mappedInd;
            }

            if(dupes[idx]){

                a[idx] += 1;
            }
            else if(flags[idx]){

                a[idx] += 1;noDupes=false;
                dupes[idx]=true;
            }
            else{
                a[idx] += 1;
                flags[idx]=true;
            }

        }


        for(iA=0;iA<=9999999;iA++){

            if(noDupes){printf("No duplicates.\n");break;}

            if(dupes[iA]){
                sprintf(buffer, "%07lu",iA);
                printf("%c%c%c-%c%c%c%c %u\n",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],a[iA]);
            }

        }

        if(cases != 0) printf("\n");
    }
}

No comments:

Post a Comment