| ||||||||||
| 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 | |||||||||
好象有要求 stable_sort()In Reply To:检查了N次,还是没发现错误,请高手指教。 Posted by:KeMu at 2006-05-16 14:19:30 > int num1,num2;
> int fan(char *p)
> { int measure=0;
> char *s,*q;
> for(s=p;s<p+num1-1;s++)
> for(q=s+1;q<p+num1;q++)
> if(*q<*s)measure++;
> return(measure);
> }
>
> #include<stdio.h>
> #include<string.h>
> int main()
> { char a[50][100],c[50];
> int b[100];
> int i,j,t;
> scanf("%d%d",&num1,&num2);
> for(i=0;i<num2;i++)
> {
> scanf("%s",a[i]);
> b[i]=fan(a[i]);
> }
>
> for(i=0;i<num2-1;i++)
> for(j=0;j<num2-1-i;j++)
> { if(b[j+1]<b[j])
> t=b[j];b[j]=b[j+1];b[j+1]=t;
> strcpy(c,a[j]);
> strcpy(a[j],a[j+1]);
> strcpy(a[j+1],c);
> }
>
> printf("\n");
> for(i=0;i<num2;i++)
> {
> for(j=0;j<num1;j++)
> printf("%c",a[i][j]);
> printf("\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