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

兄弟们,我初来乍到,被这题弄的灰头灰脑的,大家帮忙解决一下,多谢

Posted by hudedi at 2005-12-05 22:45:04 on Problem 1002
下面是我的代码,大家帮帮忙

#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define num 100000

int cmp(const void *a,const void *b)
{
    return *(long long *)a-*(long long *)b;
}
int main()
{
    static long long phone[num];
    long long times,time;
    long long duplicates=1;
    int ii,jj,kk;
    int judge=0;
    char a;
    int dic[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9};
    scanf("%I64d",&times);
    time=times ;
    phone[times-2]=-2;phone[times-1]=-2;phone[times]=-2;phone[times+1]=-2;phone[times+2]=-2;phone[times+3]=-2;/*防止出现0000000的情况*/

    while(time--)
    {
        phone[time]=0;
        for(ii=7;ii>0;)
        {
             scanf("%1s",&a);
             if(isalnum(a))
             {
                 phone[time]=isalpha(a)?10*phone[time]+dic[a-'A']:10*phone[time]+a-'0';
                 ii--;
             }
        }
    }
    qsort(phone,times,sizeof(phone[0]),cmp);
    duplicates=1;
    for(jj=0;jj<times;jj++)
    {
         if(phone[jj]==phone[jj+1]) duplicates++;
         else {
                    if(duplicates!=1)
                    {

                         printf("%d",phone[jj]/10000);
                        printf("-");
                        printf("%d ",phone[jj]%10000);
                        printf("%lld\n",duplicates);

                        judge=1;


                        duplicates=1;
                    }
              }
    }
    if(!judge) 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