| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
结构体求解In Reply To:优质算法给大家参考 Posted by:hybswan at 2010-08-07 21:19:57 #include<stdio.h>
#include<algorithm>
struct DNA
{
char c[500];
int count;
};
bool cmp(DNA s1,DNA s2)
{
return s1.count<s2.count;
}
int main()
{
DNA s[500];
int i,j,k,n,m;
scanf("%d%d\n",&n,&m); //n->length,m->number
for(i=0;i<m;i++)
scanf("%s",s[i].c);
for(i=0;i<m;i++)
{
for(j=0,s[i].count=0;j<n-1;j++)
for(k=j+1;k<n;k++)
{
if(s[i].c[j]>s[i].c[k])
s[i].count++;
}
}
std::sort(s,s+m,cmp);
for(i=0;i<m;i++)
{
printf("%s\n",s[i].c);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator