POJ1007
来源:互联网 发布:java难点 编辑:程序博客网 时间:2024/06/06 00:34
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.
most sorted” to “least sorted”. Since two strings can be equally sorted, then output them according to the orginal order.
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
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
#include<stdio.h>#include<stdlib.h>#include<string.h>struct Str{ char a[55]; int n;}str[101],t;int getinversion(char *a,int a_length){int i,j;int count=0;for( i=0;i<a_length;i++){ for( j=i+1;j<a_length;j++) { if(a[i]>a[j]) count++; }}return count;}int main(){int i,j;int length,num;scanf("%d %d",&length,&num);getchar();for( i=0;i<num;i++) { gets(str[i].a); str[i].n=getinversion(str[i].a,length); }for( i=0;i<num-1;i++) for( j=0;j<num-1-i;j++) { if(str[j].n >str[j+1].n ) { t=str[j]; str[j]=str[j+1]; str[j+1]=t; } }for( i=0;i<num;i++) puts(str[i].a);}
- poj1007
- POJ1007
- poj1007
- POJ1007
- poj1007
- POJ1007
- poj1007
- poj1007
- poj1007
- POJ1007
- poj1007
- poj1007
- POJ1007
- poj1007
- Poj1007
- poj1007
- poj1007
- POJ1007
- 解读java泛型
- Linux初识
- SharedPrefrences存值取值,第一次进入页面跳到第二个页面,第二次进入直接跳到第三个页面
- 畅销榜上的深度学习、机器学习书单!
- Java线程
- POJ1007
- 算法笔记 //08_最优合并问题
- Iterator模式的PHP实现
- 清除缓存
- beta分布介绍
- 今天,霍金没有提AI威胁论,他的新目标是带领人类移民外星球(附霍金姚期智Pete演讲实录+PPT)
- 一周AI回顾 | 南沙设立人工智能视觉图像研发中心,旷视科技C轮筹资4.6亿美元
- Android的目录分析
- nginx四种调度算法、进阶