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呢?

Posted by beiyoufeitianyu at 2005-12-30 13:57:45 on Problem 1002
#include<stdio.h>
#include<stdlib.h>
int compare(const void * a,const void * b)
{
    int i=*((int*)a);
    int j=*((int*)b);
    return i<j?-1:(i==j?0:1);
}
main()
{
   int *num,count,tmp;
   int N,i,flag;
   char ch;
   scanf("%d",&N);
   scanf("%c",&ch);
   num=(int *)malloc(N*sizeof(int));
   for(i=0;i<N;i++)
   {
      num[i]=0;
      while(1)
      {
        scanf("%c",&ch);
        if(ch=='\n') break;
        tmp=-1;
        if(ch>=48&&ch<=57)  tmp=ch-48;
        if(ch>=65&&ch<=79)  tmp=(ch-65)/3+2;
        if(ch==80||ch==82||ch==83) tmp=7;
        if(ch>=84&&ch<=86)  tmp=8;
        if(ch>=87&&ch<=89)  tmp=9;
        if(tmp!=-1) num[i]=num[i]*10+tmp;
      }
   }
   qsort(num,N,sizeof(int),&compare);
   flag=1;
   for(i=0;i<N;i++)
   {
      count=0;
      tmp=num[i];
      while(num[i]==tmp)
      {
        count++;
        i++;
      }
      if(count>1)
      {
        flag=0;
        printf("%d-%d %d\n",tmp/10000,tmp%10000,count);
      }
   }
   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