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 laoyang103 at 2011-08-02 17:24:25 on Problem 1007
#include <stdio.h>
#include <stdlib.h>
char data[1000][500] = {0};
struct Node
{
	int sum;
	int num;
};
Node mem[1000] = {0};
int cmp(const void *pa,const void *pb)
{
	return ((Node *)pa)->sum - ((Node *)pb)->sum;
}
int main()
{
	int i,j,k;
	int n,m;
	scanf("%d %d",&n,&m);
	for(i = 0;i<m;i++)
	{
		scanf("%s",data[i]);
		int sum = 0;
		for(j = 0;j<n;j++)
		{
			for(k = j+1;k<n;k++)
				if(data[i][k]<data[i][j])
					sum++;
		}
		mem[i].sum = sum;
		mem[i].num = i;
	}
	qsort(mem,m,8,cmp);
	for(i = 0;i<m;i++)
		printf("%s\n",data[mem[i].num]);
	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