Created
April 21, 2014 11:22
-
-
Save swimmi/11139881 to your computer and use it in GitHub Desktop.
Arrange from "most sorted" to "least sorted"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
//Arrange from "most sorted" to "least sorted". | |
bool comp(const string &s1, const string &s2) | |
{ | |
string s[]={s1,s2}; | |
int c[]={0,0}; | |
for(int l=0;l<2;l++) | |
for(int i=0;i<s[l].size();i++) | |
for(int j=i+1;j<s[l].size();j++) | |
if(s[l][i]>s[l][j]) c[l]++; | |
return c[1]!=c[2]?c[1]<c[2]:false; | |
} | |
int main() | |
{ | |
//ifstream cin("DNA_sorting.txt"); | |
int a,index=1; | |
cin>>a; | |
int n,m; | |
for(int i=0;i<a;i++) | |
{ | |
cin>>n>>m; | |
string s; | |
vector<string>v; | |
for(int j=0;j<m;j++) | |
{ | |
cin>>s; | |
v.push_back(s); | |
} | |
sort(v.begin(),v.end(),comp); | |
for(int j=0;j<v.size();j++) | |
cout<<v[j]<<endl; | |
if(index!=a) cout<<endl; | |
index++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment