View Code of Problem 126

#include<iostream>
#include<string>
#include<algorithm>
#include<string.h>
using namespace std;
struct Sd{
	string s;
	int nu;
	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<ss.length();i++){
				for(int j=i;j<ss.length();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;
		}
	}
}
/*
Main.cc: In function 'bool comp(Sd, Sd)':
Main.cc:12:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  if(lhs.nu<rhs.nu || lhs.nu==rhs.nu && lhs.f<rhs.f){
                      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
Main.cc: In function 'int main()':
Main.cc:27:11: error: expected ';' before 'ar'
    cin>>ss
           ^
           ;
    ar[k].s=ss;
    ~~      
Main.cc:30:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    for(int i=0;i<ss.length();i++){
                ~^~~~~~~~~~~~
Main.cc:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
     for(int j=i;j<ss.length();j++){
                 ~^~~~~~~~~~~~
*/

Double click to view unformatted code.


Back to problem 126