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

求助:我选用了稳定的插入排序法,怎么还告诉我是Wrong Answer?

Posted by speedfirst at 2005-08-14 00:02:02 on Problem 1007
我的代码:
#include <iostream>
using namespace std;

char DNAs[100][50];
int nLength, nDNANumber;
typedef struct _Measure
{
	int nValue;
	int nIndex;
} Measure;

Measure measure[50];

int main()
{
	int i, j, k;
	
	//input
	cin>>nLength>>nDNANumber;
	for(i = 0; i < nDNANumber; i++)
	{
		cin>>DNAs[i];
	}

	//calculate the measurement number
	for(i = 0; i < nDNANumber; i++)
	{
		measure[i].nIndex = i;
		for(j = 0; j < nLength - 1; j++)
		{
			for(k = j + 1; k < nLength; k++)
			{
				if(DNAs[i][j] > DNAs[i][k])
				{
					measure[i].nValue++;
				}
			}
		}
	}

	//sort the measurement value, we must use a steady sort method
	//now, I use Insertion Sort
	Measure temp;
	int min;
	for(i = 0; i < nDNANumber - 1; i++)
	{
		min = i;
		for(j = i + 1; j < nDNANumber; j++)
		{
			if(measure[min].nValue > measure[j].nValue)
			{
				min = j;
			}
		}

		if(min != i)
		{
			temp = measure[min];
			for(j = min; j > i; j--)
			{
				measure[j] = measure[j - 1];
			}
			measure[i] = temp;
		}
	}

	//output the result
	for(i = 0; i < nDNANumber; i++)
	{
		cout<<DNAs[measure[i].nIndex]<<endl;
	}

	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