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

0MS AC 贴个、、、、仅供参考

Posted by 734330469 at 2011-08-03 09:31:05 on Problem 1007
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

struct arr
{
char a[60];
};
                                                
void insertsort(int b[],int n,struct arr s[])
{	
	int x,i,j;
	struct arr y;
	for(i=1;i<n;i++)
	{	y=s[i];
		x=b[i];
		for(j=i-1;j>=0;j--)
		{
			if(x<b[j])
			{b[j+1]=b[j];
			s[j+1]=s[j];}
			else 
			break;
		}
		b[j+1]=x;
		s[j+1]=y;
	}
}

int main(int argc, char *argv[])
{
	int i,j,t,n,m,b[110]={0};
	struct arr s[110];
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
	scanf("%s",s[i].a);
	for(i=0;i<m;i++)
	for(j=0;j<n-1;j++)
	for(t=j+1;t<n;t++)
	if(s[i].a[j]>s[i].a[t])
	b[i]++;
	insertsort(b,m,s);
	for(i=0;i<m;i++)
	printf("%s\n",s[i].a);
	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