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

AC了,庆祝贴,代码贴上,呵呵,40MS,

Posted by denganliang at 2011-03-13 22:09:33 on Problem 1007
#include <stdio.h>
#include <string.h>
int main()
{
   char a[101][51],temp[51];
   int i,j,k,m,n,d[101];
   
   
   for(i=0;i<101;i++){
	   d[i]=0;
      for(j=0;j<51;j++)
         a[i][j]='\0';
         }
   scanf("%d %d",&n,&m);
   for(i=0;i<m;i++)
       scanf("%s",a[i]);

  for(i=0;i<m;i++){
	  for(j=0;j<n;j++)
	      for(k=j+1;k<n;k++){
	      if(a[i][j]>a[i][k])
	         d[i]++;
	      }
	  }
 for(i=0;i<m;i++){
    for(j=i+1;j<m;j++)
    {
		if(d[i]>d[j])
		{
			strcpy(temp,a[i]);
			strcpy(a[i],a[j]);
			strcpy(a[j],temp);
			d[i]=d[i]+d[j];
			d[j]=d[i]-d[j];
			d[i]=d[i]-d[j];
			}
		
		}

   

  }

  
  for(i=0;i<m;i++){
	  if(i>0) printf("\n");
       printf("%s",a[i]);
}
   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