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

求指点!MS上都正确,一直WA,看不出问题在哪儿。。。

Posted by qibinlou at 2012-01-26 18:48:09 on Problem 1007
#include<stdio.h>

int sort(char s[],int n)
{
 	int i,j,k=0;
 	for(i=0;i<n;i++)
 	  for(j=i+1;j<n;j++)
 	    if(s[i]>s[j])
 	      k++;
    return k;
}
int main()
{
 	int m,n;
 	printf("enter m(0<m<=100),n(0<n<=50)\n");
 	scanf("%d%d",&m,&n);
       
       
    char s[101][51];
    int rank[101];
    int i,j;
    for(i=0;i<m;i++)
      {
		 scanf("%s",s[i]);
		 rank[i]=sort(s[i],n);
	  }
  
	 int *p[101],*temp;
	 
	 for(i=0;i<m;i++)
	   p[i]=&rank[i];
	   
     for(i=0;i<m;i++)
       for(j=m-1;j>i;j--)
         if(*p[j]<*p[j-1])
           {
			  temp=p[j];
			  p[j]=p[j-1];
			  p[j-1]=temp;
		   }
		   
       printf("the arrangement is:\n");
       
       
       
       for(i=0;i<m;i++)
         printf("%s\n",s[p[i]-rank]);  
         

    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