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

代码!

Posted by chenxuan123456789 at 2012-07-28 10:41:23 on Problem 1007
#include <stdio.h>
#include <string.h>
typedef struct string
{
	char str[100];
	int sort;
}string;
string s[105];
int main()
{
	int m,n,ans,i,j,k,temp;
	char st[100];
	scanf("%d %d",&m,&n);
	for(i=0;i<n;i++)
	{
	 scanf("%s",s[i].str);
	 ans=0;
	 for(j=0;j<m;j++)
	   for(k=j+1;k<m;k++)
		 if(s[i].str[j]>s[i].str[k])
			ans++;
			 s[i].sort=ans;
	}
	 for(i=0;i<n;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
             if(s[k].sort<s[j].sort)
				 k=j;
			 if(k!=j)
			 {
				 temp=s[i].sort;
				 s[i].sort=s[k].sort;
				 s[k].sort=temp;
				 strcpy(st,s[i].str);
				 strcpy(s[i].str,s[k].str);
				 strcpy(s[k].str,st);
			 }
	}
	for(i=n-1;i>=0;i--)
	printf("%s\n",s[i].str);
	return 1;
}

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