| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 64552 | Accepted: 25498 |
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
Source
#include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,k,sum,temp;
char str[105][55];
int a[100],b[100];
scanf("%d%d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%s",str[i]);
sum=0;
for(j=0;j<strlen(str[i])-1;j++)
{
for(k=j+1;k<strlen(str[i]);k++)
{
if(str[i][k]<str[i][j])
sum++;
}
}
a[i]=sum;
b[i]=i;
}
for(i=0;i<m-1;i++)
{
for(j=0;j<m-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];a[j]=a[j+1];a[j+1]=temp;
temp=b[j];b[j]=b[j+1];b[j+1]=temp;
}
}
}
for(i=0;i<m;i++)
printf("%s\n",str[b[i]]);
return 0;
}
358



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



