POJ 1007. DNA Sorting
原题链接
简单
作者:
Hanasaki
,
2021-10-12 18:04:25
,
所有人可见
,
阅读 161
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct str
{
char a[105];
int n;
bool operator < (const str & W){return n < W.n;}
}q[105];
int sum(char a[])
{
int sum = 0;
for (int i = 0; i < strlen(a);i ++)
{
for (int j = i + 1; j < strlen(a); j ++) if (a[i] > a[j]) sum ++;
}
return sum;
}
int main()
{
int n, m; cin >> m >> n;
for (int i = 0; i < n; i ++)
{
cin >> q[i].a;
q[i].n = sum(q[i].a);
}
sort(q, q + n);
for (int i = 0; i < n; i ++) cout << q[i].a << "\n";
return 0;
}