您的位置:首页 > 其它

poj1007——DNA Sorting

2011-03-29 22:28 465 查看
发现喜欢用上了sort!操作简单、方便。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
class str
{
public:
char a[60];
int cout;
str()
{
cout=0;
}
};
str g[110];
bool cmp(str &a,str &b)
{
if(a.cout<=b.cout ) return true;
return false;
}
int main()
{
int len,m,i,j,k;
cin>>len>>m;
for(i=0;i<m;i++)
{
scanf("%s",&g[i].a );
g[i].cout =0;
for(j=0;j<len-1;j++)
for(k=j+1;k<len;k++)
if(g[i].a [j]>g[i].a [k]) g[i].cout ++;
}
sort(g,g+m,cmp);
for(i=0;i<m;i++)
printf("%s/n",g[i].a );
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: