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

首次做题一次性AC,发上来聊以纪念,求高手指点

Posted by 3902100816 at 2011-07-20 13:40:34 on Problem 1007
#include <iostream>
using namespace std;
struct DNA{char q[100];int val;};
void QuickSort(DNA *p,int headmark,int tailmark)
{
	if(headmark>=tailmark)//排序区域长度不大于1,不需再排
	{return;}

	DNA temp;
	int emp,big,small;
	temp=p[headmark];
	small=headmark;
	big=tailmark;

	while(small<big)
	{
		while(small<big && p[big].val>=temp.val)
			--big;
		p[small]=p[big];

		while(small<big && p[small].val<=temp.val)
			++small;
		p[big]=p[small];
	}
	emp=big;
	p[emp]=temp;//定位枢轴值
	QuickSort(p,headmark,emp-1);
	QuickSort(p,emp+1,tailmark);
}

int main()
{
	int i,j,k,num,len;
	while(cin>>len>>num)
	{
		DNA*p=new DNA[num+1];
		for(i=1;i<=num;i++)
		{
			cin>>p[i].q;
			p[i].val=0;
			for(j=0;j<len;j++)
			{
				for(k=j;k<len;k++)
				if(p[i].q[j]>p[i].q[k])p[i].val++;
			}
		}
		QuickSort(p,1,num);
		for(i=1;i<=num;i++)
		cout<<p[i].q<<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