Problem Description:
The inverse number can be used to describe the amount of chaos in a sequence. For example, the reverse number of "Daabec" is 5, where D is greater than the 4 number on its right,e is greater than the number of 1 on its right, 4+1=5, and the reverse number of "ZWQM" is 3+2+1+0=6. Now there are many strings of the same length, and only four letters appear in each string (A,t,c, G). Requires a program to sort the strings according to their inverse number
Input:
The first line consists of two positive integers, the first representing the string length, and the second representing the number of strings
Output:
Sorts each string by its inverse number, and if the number of reversed two strings is equal, it is arranged in the order of the two in the input
Sample input:
10 6
Aacatgaagg
Ttttggccaa
Tttggccaaa
Gatcagattt
Cccgggggga
Atcgatgcat output:
Cccgggggga
Aacatgaagg
Gatcagattt
Atcgatgcat
Ttttggccaa
Tttggccaaa
1#include <stdio.h>2#include <string.h>3 structnode4 {5 intKey//Key to save the original string number6 Charstr[ -];7}dna[ the];8 intSCharstr[])9 {Ten intsum=0, I,j; One intlen=strlen (str); A intsd[ -]={0}; - for(i=0; i<len-1; i++) - { the for(j=i+1; j<len;j++) - { - if(Str[i]>str[j]) sd[i]++; - } + } - + for(i=0; i<len;i++) sum=sum+Sd[i]; A returnsum; at } - - voidSortintRes[],intM//simple sort of a - { - inti,j,t; - for(i=0; i<m;i++) in for(j=i+1; j<m;j++) - if(res[i]>Res[j]) to { +t=Res[i]; -res[i]=Res[j]; theres[j]=T; * } $ }Panax Notoginseng - intMainvoid) the { + intn,m,i,j; A intres[ the]; thescanf"%d%d",&n,&m); + if(n>0&& n<= -&& m>0&& m<= -) - { $ for(i=0; i<m;i++) $scanf"%s",&dna[i].str); - for(i=0; i<m;i++) - { theres[i]=s (dna[i].str); -dna[i].key=Res[i];Wuyi } the sort (res,m); - for(i=0; i<m;i++) Wu for(j=0; j<m;j++) - { About if(dna[j].key==Res[i]) $ { -printf"%s\n", dna[j].str); -dna[j].key=1000000;/*This is the place ... It was an assignment, 0, and that would be problematic if the reverse degree was 0.*/ - } A } + } the return 0; -}
1104--dna Sort---Nothing to do water problem