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 yingxiang720 at 2010-08-13 15:12:50 on Problem 1007
In Reply To:优质算法给大家参考 Posted by:hybswan at 2010-08-07 21:19:57
#include<stdio.h>
#include<algorithm>

struct DNA
{
	char c[500];
	int count;
};

bool cmp(DNA s1,DNA s2)
{
	return s1.count<s2.count;
}

int main()
{
	DNA s[500];
	int i,j,k,n,m;
	scanf("%d%d\n",&n,&m);  //n->length,m->number
	for(i=0;i<m;i++)
		scanf("%s",s[i].c);
	for(i=0;i<m;i++)
	{
		for(j=0,s[i].count=0;j<n-1;j++)
			for(k=j+1;k<n;k++)
			{
				if(s[i].c[j]>s[i].c[k])
					s[i].count++;
			}
	}
	std::sort(s,s+m,cmp);
	for(i=0;i<m;i++)
	{
		printf("%s\n",s[i].c);
	}
	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