DNA Sorting
Description
You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of ``sortedness'', from ``most sorted'' to ``least sorted''. All the strings are of the same length.
Input
Output
Sample Input
10 6 AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT
Sample Output
CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA
#include <stdio.h> #include <string.h> typedef struct{ char sList[51]; int len; }dna; int dna_list(dna sz, int n) { int i,j,ret = 0; for(i = 0; i < n-1; i++) { for(j = i+1; j < n; j++) if(sz.sList[i] > sz.sList[j]) ret++; } return ret; } void Qsort(dna sz[], int m) { int i,j; dna temp; for(i = 0; i < m-1; i++) { for(j = 0; j < m-i-1; j++) { if(sz[j].len > sz[j+1].len) { temp = sz[j]; sz[j]= sz[j+1]; sz[j+1]= temp; } } } } void display(dna sz[], int m) { int i; for(i = 0; i < m; i++) { printf("%s\n",sz[i].sList); } } int main() { int n,m; scanf("%d%d",&n,&m); dna sz[100]; int i,j; for( i = 0; i < m; i++) { scanf("%s",&sz[i]); sz[i].len = dna_list(sz[i],n); } Qsort(sz,m); display(sz,m); }
402



被折叠的 条评论
为什么被折叠?



