#include <iostream>
#include <string>
#include <map>
using namespace std;
class DNA{
public:
string strDNA;
DNA(string);
};
DNA::DNA(string s)
{
strDNA = s;
}
int calculateInversionsNum(const string&);
bool operator<(const DNA&, const DNA&);
int main ()
{
string str;
int iNum;
int iLength;
cin >> iLength >> iNum;
map<DNA, int> mDna;
while (iNum--)
{
cin >> str;
DNA d = DNA(str);
++mDna[d];
}
map<DNA, int>::iterator iterI = mDna.begin();
while(iterI != mDna.end())
{
while (iterI->second --)
{
cout << iterI->first.strDNA << endl;
}
iterI ++;
}
return 0;
}
bool operator<(const DNA& dL, const DNA& dR)
{
if(calculateInversionsNum(dL.strDNA) < calculateInversionsNum(dR.strDNA))
{
return true;
}
else
{
return false;
}
}
int calculateInversionsNum(const string& str)
{
int i = 0;
int iInversionsNum = 0;
while (i < str.size() - 1)
{
int iCountRepeat = 1;
while (str[i] == str[i + 1])
{
iCountRepeat ++;
i++;
if (i == str.size() - 1)
{
return iInversionsNum;
}
}
int j = i;
int iAdd = 0;
while (j < str.size())
{
if (str[i] > str[j])
{
iAdd ++;
}
j ++;
}
iInversionsNum += iCountRepeat * iAdd;
i ++;
}
return iInversionsNum;
}
分享到:
相关推荐
北大POJ1007-DNA Sorting 解题报告+AC代码
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 34868 Accepted: 13480 Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1440解题报告 poj 1440解题报告 poj 1440解题报告 poj 1440解题报告
poj 3083解题报告poj 3083解题报告poj 3083解题报告poj 3083解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
poj 3720解题报告poj 3720解题报告poj 3720解题报告poj 3720解题报告
poj1691解题报告 题目来源:http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=1691(POJ No.1691) 解法: 搜索
poj2828解题报告,希望能帮到志同道合的算法爱好者
北大poj解题报告,希望能帮到软件工程的同学,每天一道,持之以恒,熟能生巧,与您共勉!
poj dna sorting 问题,研究的ac coderrrrrrr
北大ACM1316解题报告
Problem 1061 青蛙的约会 poj解题报告。有源码。可直接提交C++实现
ACM Poj Pku 解题报告答案 打包 下载 600多题 史上最全 不是网上乱传的200多题,更不是100多题就挂着10分才能下的题 下了这个 大家也不要浪费分数去下载其它版本的了,基本上都有 共享 一起进步 中国加油 ACMer...
这是我发的第二篇解题报告,写的不怎么的。呵呵!!!!!
ACM POJ 解题报告北大POJ 大量解题代码
北大ACM在线评测系统POJ的题目解题报告。涵盖各种类型的acm题目。值得参考借鉴。打包下载。