Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
附个简单的代码#include <iostream> #include <cmath> #include <algorithm> #define MAX 100 using namespace std; int sortedness(char *); typedef struct DNA { char * str; int sortedness; }dna; int cmp(const void * a, const void * b){ return (((dna*)a)->sortedness - ((dna*)b)->sortedness); } int main() { int length,rows; cin>>length>>rows; dna* arr = new dna[rows]; for(int i=0;i<rows;i++){ arr[i].str = new char[length+1]; cin>>arr[i].str; arr[i].sortedness = sortedness(arr[i].str); //cout<<arr[i].sortedness<<endl; } qsort(arr,rows,sizeof(dna),cmp); for(int i=0;i<rows;i++){ cout<<arr[i].str<<endl; } return 0; } int sortedness(char *str) { int a[4]={0,0,0,0}; int cnt=0; for(int i=0;str[i]!='\0';i++){ switch(str[i]) { case 'A': a[0]++; cnt+= a[1]+a[2]+a[3]; break; case 'C': a[1]++; cnt+=a[2]+a[3]; break; case 'G': a[2]++; cnt+=a[3]; break; case 'T': a[3]++; break; } } return cnt; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator