标签:name string main ++ bool poj logs space 简单
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
int n,l;
struct DNA
{
string s;
int unnum;//逆序数
};
bool cmp(DNA a,DNA b)
{
return a.unnum<b.unnum;
}
int nxs(string s)
{
int t=0;
for(int i=0;i<l;i++)
for(int j=i+1;j<l;j++)
{
if(s[i]>s[j])
t++;
}
return t;
}
int main()
{
cin>>l>>n;
DNA p[n+1];
for(int i=0;i<n;i++)
{
cin>>p[i].s;
p[i].unnum=nxs(p[i].s);
}
sort(p,p+n,cmp);
for(int i=0;i<n;i++)
cout<<p[i].s<<endl;
}
简单易懂的代码;
标签:name string main ++ bool poj logs space 简单
原文地址:http://www.cnblogs.com/masterchd/p/6772401.html