View Code of Problem 126

#include<stdio.h>
#include<string.h>
struct s{
	char d[100];
}dna[100],temp;
int main()
{
	int i,j,n,m,temp1;
	int count[100]={0};
	while(scanf("%d%d",&n,&m)==2)//m个数 
	{
		for(i=0;i<m;i++)
		{
			scanf("%s",dna[i].d);
		}
		
		for(i=0;i<m;i++)
		{  count[i]=0;
			for(j=0;j<n;j++)
			{
				if(dna[i].d[j]=='A')
				    count[i]=count[i]+0;
				else
				    for(int s=j;s<n;s++)
				    {
				    	if(dna[i].d[s]<dna[i].d[j])
				    	     count[i]=count[i]+1;
					}
			}
		}
		
		for(i=0;i<m;i++)
		{
			for(j=i;j<m;j++)
		    {
					if(count[i]>count[j])
		    	{
		    		temp=dna[i];
		    		dna[i]=dna[j];
		    		dna[j]=temp;
		    		temp1=count[i];
		    		count[i]=count[j];
		    		count[j]=temp1;
				}
	    	}
		}
		
		for(i=0;i<m;i++)
		{
			printf("%s\n",dna[i].d);
		}
		
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 126