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 xmu0633 at 2009-08-24 22:32:31 on Problem 1007
牛人帮忙看看哈
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;

struct DNA{
	string s;
	int num;
};
struct DNA  a[100];

int comp(const void *a,const void *b){
	return ((struct DNA*)a)->num > ((struct DNA*)b)->num;
}

int main(){
	string s;
	int num,n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		num=0;
		cin>>a[i].s ;
		for(int j=0;j<n-1;j++){
			for(int k=j+1;k<n;k++)
				if(a[i].s[j]>a[i].s[k])
					num++;
		}
		a[i].num=num;
	}
	qsort(a,m,sizeof(a[0]),comp);
	for(int i=0;i<m;i++){
		cout<<a[i].s<<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