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 alaalabuku at 2015-07-05 11:41:37 on Problem 1007
#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:
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