Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 60701 | Accepted: 23971 |
Description
Input
Output
Sample Input
10 6 AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT
Sample Output
CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA
Source
#include
#include
#include
#include
using namespace std;
typedef struct pair {
string s;
int inversion;
}Pair;
int calc_inversion(string s, int length)
{
int sum = 0;
int A = 0;
int C = 0;
int G = 0;
int T = 0;
// 从后向前,一次遍历
for(int i = length - 1; i >= 0; --i) {
switch(s[i]) {
case 'A':
++A;
break;
case 'C':
sum += A;
++C;
break;
case 'G':
sum += A + C;
++G;
break;
case 'T':
sum += A + C + G;
++T;
break;
default:
break;
}
}
return sum;
}
bool comp(const Pair& p1, const Pair& p2) {
return p1.inversion <= p2.inversion;
}
int main()
{
int n, length;
cin >> length >> n;
vector vec;
for(int i = 0; i != n; ++i) {
Pair p;
cin >> p.s;
p.inversion = calc_inversion(p.s, length);
vec.push_back(p);
}
sort(vec.begin(), vec.end(), comp);
for(vector::iterator beg = vec.begin();
beg != vec.end();
++beg) {
cout << beg->s << endl;
}
}