| ||||||||||
| 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 | |||||||||
求助先化成数,然后shell排序,在进行输出,不知道错在哪里,请各位大牛们看看。
不胜感激。
#include<stdio.h>
void shellsort(int *a,int n)
{
int gap,i,j,t;
gap=n/2;
while(gap>0)
{
for(i=gap+1;i<=n;i++)
{
j=i-gap;
while(j>0)
{
if(*(a+j)>*(a+j+gap))
{
t=*(a+j);
*(a+j)=*(a+j+gap);
*(a+j+gap)=t;
j=j-gap;
}
else
j=0;
}
}
gap=gap/2;
}
}
int main()
{
long n,m,a[100002],b[8]={1000000,100000,10000,1000,100,10,1},i,j,t,count;
char s[17],tag;
scanf("%ld",&n);
m=n;
while(n>0)
{
a[n]=0;
i=0;
j=0;
scanf("%s",s);
while(i<8)
{
if(s[j]!='-')
{
if(s[j]<='9')
a[n]=a[n]+(s[j]-'0')*b[i];
else
{
t=s[j]-'A';
if(s[j]>'Q')
t--;
a[n]=a[n]+(t/3+2)*b[i];
}
i++;
}
j++;
}
n--;
}
shellsort(a,m);
tag='N';
i=1;
while(1)
{
j=i;
count=0;
while(a[i]==a[j]&&j<m)
{
j++;
count++;
}
if(count>1)
{
tag='Y';
printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,count);
}
i=j;
if(i==m)
break;
}
if(tag=='N')
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