C语言pojDNA字符串问题
来源:互联网 发布:霍华德生涯得分数据 编辑:程序博客网 时间:2024/06/05 16:11
DNA Sorting
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 104426 Accepted: 41805
Description
One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC'', this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence ``AACEDGG'' has only one inversion (E and D)---it is nearly sorted---while the sequence ``ZWQM'' has 6 inversions (it is as unsorted as can be---exactly the reverse of sorted).
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.
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
The first line contains two integers: a positive integer n (0 < n <= 50) giving the length of the strings; and a positive integer m (0 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.
Output
Output the list of input strings, arranged from ``most sorted'' to ``least sorted''. Since two strings can be equally sorted, then output them according to the orginal order.
Sample Input
10 6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT
Sample Output
CCCGGGGGGAAACATGAAGGGATCAGATTTATCGATGCATTTTTGGCCAATTTGGCCAAA
#include<stdio.h>#include<string.h>char s[101][51];int a[101];int n,m;void sort();int main(){int i,j,k;scanf("%d%d",&n,&m);for(i=0;i<m;i++){char c=getchar();for(j=0;j<n;j++){scanf("%c",&s[i][j]);}}sort();int flag=1;i=0;int l=0;L:for(i=0;i<m;i++){for(j=0;j<m;j++){if(a[j]!=10000000)l=1;}if(a[i]==10000000)continue;flag=1;if(i==m-1){printf("%s\n",s[i]); a[i]=10000000;goto L; }for(j=i+1;j<m;j++){if(a[j]==10000000)continue;if(a[i]>a[j]){flag=0;break; }} if(flag==1){for(k=0;k<n;k++){printf("%c",s[i][k]);}printf("\n");a[i]=10000000;goto L;}if(l==0)break; }}void sort(){int i,j,k,flag=1;for(i=0;i<m;i++){int num=0;for(j=0;j<n-1;j++){for(k=j+1;k<n;k++){if(s[i][j]>s[i][k]){num++;}}}a[i]=num;}}
阅读全文
0 0
- C语言pojDNA字符串问题
- c语言字符串问题
- c语言中的字符串问题
- C语言读取字符串问题
- 字符串读入问题 (C语言)
- c语言字符串排序问题
- c语言重组字符串问题
- 问题 C: C语言习题 字符串长度
- c语言中关于字符串反转问题
- C语言字符串输出问题&str[i]
- 关于c语言中的字符串问题
- 关于c语言中的字符串的问题
- c语言字符串变量赋值问题
- c语言关于字符串常量的问题
- (C语言)字符串反转相关问题
- C语言的字符串倒置问题
- 笔试题:C语言中的字符串问题
- 问题 D: C语言习题 字符串比较
- 那些年mui webview遇到的坑
- HDOJ Repair the Wall JAVA 2124
- angular模糊查询和过滤修改
- Lambda Expressions(Sort)
- 服务端连接数据库
- C语言pojDNA字符串问题
- 【C++】动态规划方法以及Maximum Length of Repeated Subarray
- hook的LD_PRELOAD用法
- 替换空格:
- dokuwiki
- 第一个博客记录成长
- EA&UML日拱一卒-多任务编程超入门-(6)小人国里的积木山
- Samba配置文件常用参数详解
- springmvc常用注解详解