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

Re:我用结构体,然后排序,怎么不行呢

Posted by zsc08_wangqiang at 2010-02-16 16:08:56 on Problem 1007
In Reply To:我用结构体,然后排序,怎么不行呢 Posted by:xmu0633 at 2009-08-24 22:32:31
> 牛人帮忙看看哈
> #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;
> }

可能是这里吧,,改为:
int comp(const void *a,const void *b){
> 	return (*(DNA*)a).num > (*(DNA*)b).num;
> }


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