您的位置:首页 > 其它

poj 1007 DNA Sorting

2016-12-06 20:00 417 查看
poj 1007 DNA Sorting

题意:将字符串以逆序数的大小排序。

题解:rt。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
struct xx
{
char str[51];
int num;
}a[101];
int cmp(xx a,xx b)
{
return a.num < b.num;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i = 0; i < m; i++)
{
scanf("%s",a[i].str);
for(int j = 0; j < n - 1; j++)
{
for(int k = j + 1; k < n; k++)
{
if(a[i].str[j] > a[i].str[k])
a[i].num++;
}
}
}
sort(a,a+m,cmp);
for(int i = 0; i < m; i++)
{
printf("%s\n",a[i].str);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: