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 2120120811 at 2014-05-15 21:20:18 on Problem 1007
#include "stdafx.h"
#include <algorithm>
#include <iostream>
using namespace std;
int CalMeasure(char *ch, int m);
struct DNA
{
	char *ch;
	int num;
};
bool compare(DNA a, DNA b)
{
	if(a.num<b.num)
		return 1;
	else 
		return 0;
}
int main()
{
	int m,n;
	cin>>m>>n;
	int i,j;
	DNA *DNAList=new DNA[n];
	for(i=0;i<n;i++)
	{
		cin.clear();
		cin.sync(); 
		DNAList[i].ch=new char[m];
		cin.getline(DNAList[i].ch,m+1,'\n');
		DNAList[i].num=CalMeasure(DNAList[i].ch, m);
	}
	
	stable_sort(DNAList,DNAList+n,compare);

	for(i=0;i<n;i++)
	{
		cout<<DNAList[i].ch<<endl;
	}

	return 0;

}
int CalMeasure(char *ch, int m)
{
	if(m==1)
		return 0;
	int sum=0;
	int i;
	int j;
	for(i=0;i<m-1;i++)
	{
		for(j=i+1;j<m;j++)
		{
			if(ch[i]>ch[j])
			{
				sum++;
			}
		}
	
	}
	return sum;
}

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