Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA的同学注意了,字符串末位需加'\0',WA无数次的可以试试,觉得好用的请告诉我为什么

Posted by biglemon at 2012-02-09 16:30:49 on Problem 1002
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int Comp(const void *p1,const void *p2)
{
    return strcmp((char *)p1,(char *)p2);
}

int main()
{
    char to[]={"22233344455566677778889999"};
//  char alphaToNum[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int n,i,j,l,num,len;
    char p[101000][9];
    char a[1000];
    int flag;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",a);
        j=0;
        for(l=0,len=strlen(a);l<len;l++){
            if('A'<=a[l]&&a[l]<='Z')
                p[i][j++]=to[a[l]-'A'];
            else if('0'<=a[l]&&a[l]<='9')
                p[i][j++]=a[l];
            if(j==3)
                p[i][j++]='-';
        }
        p[i][8]='\0';////如果没有这句WA,添这句AC,注意注意!!!!!!
    }

    qsort(p,n,sizeof(p[0]),Comp);

    flag=1;
    for(i=0;i<n;i=j){
        num=0;
        for(j=i;j<n&&!strcmp(p[i],p[j]);j++)
            num++;
        if(num>1){
            printf("%s %d\n",p[i],num);
            flag=0;
        }
    }
    if(flag)
        printf("No duplicates.\n");

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator