Introduction to Nanyang oj--Language--from small code

Source: Internet
Author: User

4.ASCII sorting-Learn to insert sort

ASCII-code Ordering
Time limit: Ms | Memory Limit: 65535 KB
Difficulty: 2

Describe
After entering three characters (which can be repeated), the ASCII code of each character is printed in the order of three characters from small to large.

Input
The first line enters a number n, which indicates that there are n sets of test data. The next n rows enter multiple sets of data, each with a row of three characters and no spaces between them.
Output
For each set of input data, the output line is separated by a space between the characters.
Sample input

3
Qwe
Asd
Zxc

Sample output

E Q W
A D S
c x Z

#include <stdio.h> #include <string.h>/** *  @brief   Insert sort  *  @param  array   Array to sort  *  @param  len  length of the array  *  @return  */int sortinsert ( char  * elem_array, int len ) {    if ( null == elem_ array | |  0 >= len ) {        return -1;     }    int i = 1;    int j = 0 ;     for ( ; i < len; i++ ) {         if ( elem_array[i] < elem_array[i-1]) {                 char tmp = elem_array[i];                 for ( j =  i - 1; j >= 0 && elem_array[j] > tmp; j--) {                     elem_array[j+1] = elem_array[j];                  }                 elem_array[j+1] = tmp;        }     }    return 0;} Int main ( void ) {    int n = 0;    scanf ("%d", &n);     char charr[4];        while (n--) {        scanf ("%s", Charr);         sortinsert (charr,3);         printf ("%c %c %c\n", charr[0],charr[1],charr[2]);    }             return 0;}


Introduction to Nanyang oj--Language--from small code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.