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

要出人命了,我都测试了n组数据了,为什么还老说我wa,谁帮我看看啊,

Posted by lnnulc2005 at 2008-04-12 19:24:52 on Problem 1007
#include <iostream>
#include <cstring>

using namespace std;

struct DNA 
{	
	char *str;	
	int sort_value;		
};


int BinaryCode(DNA *dna,int loop,int i)
{
	int binaryflag = 0;
	if(dna[loop].str[i]=='A')	binaryflag = 8;
	if(dna[loop].str[i]=='C')	binaryflag = 4;
	if(dna[loop].str[i]=='G')	binaryflag = 2;
	if(dna[loop].str[i]=='T')	binaryflag = 1;

	return binaryflag;
}


int CalculateUnsortedness(DNA *dna,int loop,int bit_value)
{
	int unsortedness = 0;

	for(int i=bit_value-1;i>0;i--)
	{
		int binaryflag1 =BinaryCode(dna,loop,i);		

		for(int j=i-1;j>=0;j--)
		{
			int binaryflag2 = BinaryCode(dna,loop,j);

			if(dna[loop].str[i]<dna[loop].str[j]&&(binaryflag1&binaryflag2)==0)
			{
				binaryflag1 +=binaryflag2;
				unsortedness++;
			}
		}
	}

	dna[loop].sort_value = unsortedness;

	return 0;
}

int Sort(DNA *dna,int list_count,int bit_value)
{
	int i,j;
	DNA temp;
	temp.str = new char[bit_value];

	for(i=1;i<list_count;i++)
	{
		temp.sort_value = dna[i].sort_value;
		strncpy(temp.str,dna[i].str,bit_value);
		j = i -1;
		while(temp.sort_value<dna[j].sort_value)
		{
			dna[j+1].sort_value = dna[j].sort_value;
			strncpy(dna[j+1].str,dna[j].str,bit_value);
			j--;
			dna[j+1].sort_value = temp.sort_value;
			strncpy(dna[j+1].str,temp.str,bit_value);
			if(j<0)		break;
		}		
	}

	delete [] temp.str;
	return 0;
}


int main(void)
{	
	int bit_value,list_count;

	while(cin>>bit_value>>list_count)
{

	DNA *dna = new DNA[list_count];
	for(int loop=0;loop<list_count;loop++)
	{
		dna[loop].str = new char[bit_value+1];
		memset(dna[loop].str,0,(bit_value+1)*sizeof(char));
	}
	
	char buff[100];	
	int iloop=0;
	
	while(iloop<list_count)
	{
		memset(buff,0,sizeof(buff));
		cin>>buff;
		strncpy(dna[iloop].str,buff,bit_value);	
		CalculateUnsortedness(dna,iloop,bit_value);
		iloop++;
	}	
	
	Sort(dna,list_count,bit_value);

	for(int loop=0;loop<list_count;loop++)
	{
		cout<<dna[loop].str<<endl;		
	}
	
	
	for(int loop=0;loop<list_count;loop++)
	{
		delete [] dna[loop].str;
	}
	
	delete [] dna;
}

	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