OJ Problem--ascii Code sort

Source: Internet
Author: User

/*
* Copyright (c) 2014, Yantai University School of Computer Science
* All rights reserved.
* File name: test.cpp
* Author: Xiaokai
* Completion Date: May 19, 2015
* Version Number: v1.0
*
* Description of the problem:
* Input Description:
* Program output:

*/

After the title description enters three characters, the ASCII code of each character outputs the three characters in the order from small to large. There are several groups of input input data, one row for each group, three characters, and no spaces between them. Output for each set of input data, output one line, the middle of the character separated by a space. Sample input
Qweasdzxc
Sample output
e q wa d SC x z
Code:
#include <iostream> #include <cstdio>using namespace Std;int main () {    char a[3],t;    int i,j;    while (gets (a))    {for        (i=0, i<3; ++i) for            (j=0; j<3; ++j)                if (a[j]>a[j+1])                {                    t=a[j];                    A[J]=A[J+1];                    a[j+1]=t;                }        cout<<a[0]<< "" <<a[1]<< "" <<a[2]<<endl;    }    return 0;}

Study Summary: This topic, good depressed Ah! , submitted several times, finally succeeded, is not know, why while (get (a)) and while (1) {gets (a) the latter of the two formulations of why output overrun, kneeling for the big God solution, the same calculation faster, more efficient algorithm, thanked.

OJ Problem--ascii Code sort

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.