View Code of Problem 126

#include<iostream>
#include<string>
#include<algorithm>
#include<string.h>
using namespace std;
struct Sd{
	string s;
	int nu=0;
	int f;
};
bool comp(Sd lhs,Sd rhs){
	if(lhs.nu<rhs.nu || lhs.nu==rhs.nu && lhs.f<rhs.f){
		return true;
	}
	else{
		return false;
	}
}
int main(){
	int n,m;
	while(cin>>n>>m){
		Sd ar[1000];
		int k=-1;
		while(m--){
			k++;
			string ss;
			cin>>ss;
			ar[k].s=ss;
			ar[k].f=k;
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					if(ss[i]=='A'){
						break;
					}
					else if(ss[i]=='C'){
						if(ss[j]=='A'){
							ar[k].nu++;
						}
					}
					else if(ss[i]=='T'){
						if(ss[j]=='A' || ss[j]=='C' || ss[j]=='G'){
							ar[k].nu++;
						}
					}
					else if(ss[i]=='G'){
						if(ss[j]=='A' || ss[j]=='C'){
							ar[k].nu++;
						}
					}
				}
			}
		}
		sort(ar,ar+k+1,comp);
		for(int i=0;i<=k;i++){
			cout<<ar[i].s<<endl;
		//	cout<<ar[i].nu<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 126