题目描述:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 44730 | Accepted: 17445 |
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
//accepted
#include"iostream"
#include"stdio.h"
#include"string.h"
using namespace std;
typedef struct st_chars
{
int count;
char s[50];
}st_chars;
int main()
{
int n;//串长度
int m;//串个数
cin>>n;
cin>>m;
st_chars *chars=new st_chars[m];
int i;
int j;
for( i=0;i<m;i++)
{
chars[i].count=0;
cin>>chars[i].s;
}
for( j=0;j<m;j++)
{
for(i=0;i<n-1;i++)
{
int k=0;
while(k<n-1-i)
{
if(chars[j].s[i]>chars[j].s[i+k+1]){++chars[j].count;++k;}
else ++k;
}
}
}
st_chars temp;
for(i=0;i<m-1;i++)
{
if(chars[i].count<chars[i+1].count)continue;
else
{
temp=chars[i+1];
j=i;
while(chars[j].count>temp.count)
{
chars[j+1]=chars[j];
--j;
}
chars[j+1]=temp;
}
}
for(i=0;i<m;i++)
cout<<chars[i].s<<endl;
return 1;
}
1511

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



