Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

优质算法给大家参考

Posted by hybswan at 2010-08-07 21:19:57 on Problem 1007
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator