#include "stdio.h"
#include "string.h"
#include "stdlib.h"
typedef struct th {
char word[55];
int sort;
} DNA;
DNA str[110]={0,0};
int cmp(const void *a, const void *b) {
return (((DNA *)a)->sort-((DNA *)b)->sort);
}
int main() {
int i, j, k, t, n, m;
char blank[10];
scanf("%d",&t);
getchar();
while (t--) {
gets(blank);
scanf("%d %d",&n,&m);
for (i=0 ; i<m ; i++) {
str[i].sort=0;
scanf("%s",str[i].word);
for (j=0 ; j<n ; j++) {
for (k=j+1 ; k<n ; k++) {
if (str[i].word[j]>str[i].word[k]) {
str[i].sort++;
}
}
}
}
qsort(str,m,sizeof(DNA),cmp);
for (i=0 ; i<m ; i++) {
printf("%s\n",str[i].word);
}
if (t) printf("\n");
getchar();
}
return 0;
}
Thursday, September 02, 2010
[UVa] 612 - DNA Sorting
Very simple if you think with Structures and stdlib's qsort. Nothing can beat you. No blank line at the end and this is counting your solved list up.
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Install MinGW GCC Port on Windows. 1. Just go to this address [ http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ ]...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.