Chinaunix首页 | 论坛 | 博客
  • 博客访问: 434710
  • 博文数量: 103
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 971
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-11 17:22
文章分类
文章存档

2008年(77)

2007年(26)

我的朋友

分类: C/C++

2008-03-17 18:48:02

#include <stdio.h>
#include <stdlib.h>

char array[101][51];
int sort[100];

int main(int argc, char **argv)
{
        int n, m, i, j, k, key, pos;
        int res[100];

        scanf("%d %d", &n, &m);
        getchar();

        for(i = 0; i < m; i++){
                for(j = 0; j < n; j++){
                        scanf("%c", &array[i][j]);
                }
                getchar();
        }

        for(i = 0; i < m; i++){
                for(j = 0; j < n; j++){
                        for(k = j; k < n; k++){
                                if(array[i][j] > array[i][k]){
                                        sort[i]++;
                                }
                        }
                }
                res[i] = i;
        }//算逆序数

        for(j = 1; j < m; j++){
                i = j-1;
                key = sort[j];
                pos = res[j];
                while((key < sort[i]) && (i >= 0)){
                        sort[i+1] = sort[i];
                        res[i+1] = res[i];
                        i--;
                }
                sort[i+1] = key;
                res[i+1] = pos;
        }//插入排序

        for(i = 0; i < m; i++){
                printf("%s\n", array[res[i]]);
        }

        exit(0);
}

阅读(711) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~