zoukankan      html  css  js  c++  java
  • ASCII码排序

    ASCII码排序

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
     
    描述
    输入三个字符(可以重复)后,按各字符的ASCII码从小到大的顺序输出这三个字符。
     
    输入
    第一行输入一个数N,表示有N组测试数据。后面的N行输入多组数据,每组输入数据都是占一行,有三个字符组成,之间无空格。
    输出
    对于每组输入数据,输出一行,字符中间用一个空格分开。
    样例输入
    3
    qwe
    asd
    zxc
    样例输出
    e q w
    a d s
    c x z
     1 #include <stdio.h>
     2 
     3 #define SIZE 3
     4 
     5 int main()
     6 {
     7     char array[SIZE];
     8     int times;
     9 
    10     scanf("%d", &times);
    11 
    12     while(times > 0)
    13     {
    14         int i = 0;
    15         char min;
    16         
    17         scanf("%s", &array[0]);                                //输入要排序的字符串
    18 
    19         for(; i < SIZE; i ++)                                //选择排序对字符数组排序
    20         {
    21             int j = 0;
    22             int min = i;
    23             
    24             for(j = i; j < SIZE; j ++)                        //找出剩下最小的放到数组前面
    25             {
    26                 if(array[j] <= array[min])
    27                     min = j;
    28             }
    29             if(min != i)                                    //交换
    30             {
    31                 char temp = array[i];
    32                 array[i] = array[min];
    33                 array[min] = temp;
    34             }
    35         }
    36                                         //输出结果
    37         for(i = 0; i < SIZE; i ++)
    38         {
    39             printf("%c ", array[i]);
    40         }
    41         printf("
    ");
    42         times --;
    43     }
    44 }
  • 相关阅读:
    Pascal's Triangle II
    Pascal's Triangle
    Path Sum II
    Path Sum
    plusOne
    Divide Two Integers
    64. ZigZag Conversion
    63. Swap Nodes in Pairs && Rotate List && Remove Nth Node From End of List
    62. Divide Two Integers
    61. Unique Paths && Unique Paths II
  • 原文地址:https://www.cnblogs.com/luckygxf/p/3678287.html
Copyright © 2011-2022 走看看