天天看点

POJ1007 DNA Sorting 水题

题意:给你一个DNA的序列,给定逆序数的定义,叫你按逆序数从小到大排序输出。

其实很简单。

只不过为了排序,弄个结构体出来比较方便。

#include<iostream>
#include<queue>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#include<algorithm>
using namespace std;
const int N=55,M=105;
int n,m;
char str[M][N];
struct Node
{
	int id,num;
}node[M];
int a,c,g,t;
int count(char a)
{
	switch(a)
	{
	case 'A':
		a++;
		return c+g+t;
		
	case 'C':
		c++;
		return g+t;
		
	case 'G':
		g++;
		return t;
	case 'T':
		t++;
		return 0;
	}
}
bool cmp(const Node&a,const Node&b)
{
	return a.num<b.num;
}
int main()
{
	scanf("%d%d",&n,&m);
	
	for(int i=1;i<=m;i++)
	{
		a=0,t=0,g=0,c=0;
		scanf("%s",str[i]+1);
		node[i].id=i;
		for(int j=1;j<=n;j++)
		{
			node[i].num+=count(str[i][j]);
		}
	}
	sort(node+1,node+m+1,cmp);
	for(int i=1;i<=m;i++)
		printf("%s\n",str[node[i].id]+1);
	return 0;
}