| ||||||||||
| 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 | |||||||||
优质算法给大家参考#include"stdio.h"
#include"string.h"
#include"stdlib.h"
int cmp(const void * a, const void * b){
return((*(int*)a-*(int*)b));
}
void main(){
int n,m,i,j;
char str[100][53];
int st[100];
scanf("%d%d",&n,&m);
for (i=0;i<m;i++){
int len,j,k,flag;
scanf("%s",&str[i]);
len=strlen(str[i]);
for(flag=0,j=1;j<len;j++){
for(k=0;k<j;k++){
if(str[i][k]>str[i][j]) flag++; //计算DNA系列的秩
}
}
st[i]=flag*1000+i ; //将秩和原来的下标绑定
}
qsort(st,m,sizeof(st[0]),cmp);//对秩和下标绑定的数组排序
for(i=0;i<m;i++){
printf("%s\n",str[st[i]%1000]);//输出新的DNA序列
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator