|  | 
 
 发表于 2020-12-12 19:55:12
|
显示全部楼层
   本楼为最佳答案 
| 本帖最后由 jackz007 于 2020-12-12 19:58 编辑 
 排序的要点是要对有先后次序的两个数做比较,合乎要求的维持原样,否则就交换位置。但是,在楼主的代码中,却没有看到有这样的比较。
 
 复制代码#include<stdio.h>
#include<string.h>
#define M 50
int main(void)
{
        char str[M] , temp                      ;
        int i , j , m                           ;
        scanf("%s" , str)                       ;
        for(m = strlen(str) , i = 1 ; i < m - 2 ; i += 2) {
                for(j = i + 2 ; j < m ; j += 2) {
                        if(str[j] < str[i]) {
                                temp = str[i]   ;
                                str[i] = str[j] ;
                                str[j] = temp   ;
                        }
                }
        }
        printf("%s\n", str)                     ;
}
编译、运行实况
 
 复制代码D:\00.Excise\C>cl x.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
x.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/out:x.exe
x.obj
D:\00.Excise\C>x
a9b8c7d6e5f4g3h2i1j0
a0b1c2d3e4f5g6h7i8j9
D:\00.Excise\C>
 | 
 |