| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怎么一直WA呢?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator