#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct DNAChain
{
string chain;
int measure;
};
int compare(const DNAChain& chain1, const DNAChain& chain2)
{
return chain1.measure < chain2.measure;
}
int calculateMeasure(const string& chain)
{
int numA = 0, numC = 0, numG = 0, numT = 0;
int numTotal = 0;
for(int i = chain.size() - 1; i >= 0; i--)
{
switch(chain[i])
{
case 'A':
{
numA++;
break;
}
case 'C':
{
numC++;
numTotal += numA;
break;
}
case 'G':
{
numG++;
numTotal += (numA + numC);
break;
}
case 'T':
{
numT++;
numTotal += (numA + numC + numG);
break;
}
}
}
return numTotal;
}
int main()
{
vector<DNAChain> m_dnaSort;
int n,m;
cin >> n >> m;
while((--m) >= 0)
{
DNAChain dnaNode;
string dnaString;
cin >> dnaString;
dnaNode.measure = calculateMeasure(dnaString);
dnaNode.chain = dnaString;
m_dnaSort.push_back(dnaNode);
}
sort(m_dnaSort.begin(), m_dnaSort.end(), compare);
for(int i = 0; i < m_dnaSort.size(); i++)
{
cout << m_dnaSort[i].chain << endl;
}
}
poj 1007
最新推荐文章于 2021-02-23 15:33:11 发布