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 20113103708 at 2012-06-10 18:10:26 on Problem 1007
#include <stdio.h>
#include <stdlib.h>

struct node
{
	int sum;    //n_inversion
	int number; //input consequence
	char s[51];//information
}str[101];

int n_inversion(char a[],int lg)
{
	int n_in=0;
	for(int i=0;i<lg-1;i++)
		for(int j=i+1;j<lg;j++)
			if(a[i]>a[j]) n_in++;
	return n_in;
}

int cmp(const void* a,const void* b)//if a>b?
{
	if( ((node *)a)->sum > ((node *)b)->sum) return 1;
	else if(((node *)a)->sum==((node *)b)->sum) return ((node *)a)->number>((node *)b)->number?1:0;
	else return 0;
}

int main()
{
	int length,num;
	char temp[51];
	scanf("%d%d",&length,&num);
	for(int i=0;i<num;i++)
	{
		scanf("%s",temp);
		int j=0,k=0;
		while(temp[j]!='\0')
		{
			if(temp[j]=='A'||temp[j]=='C'||temp[j]=='G'||temp[j]=='T')
			{
				str[i].s[k]=temp[j];
				j++;k++;
			}
			else
			{
				j++;
			}
		}
		str[i].s[k]='\0';

		str[i].sum=n_inversion(str[i].s,k+1);
		str[i].number=i;
	}

	qsort(str,num,sizeof(str[0]),cmp);

	for(int i=0;i<num;i++)
	{
		printf("%s\n",str[i].s);

	}
	system("PAUSE");

	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