Use % * C to filter out carriage return and sort by ASCII code

Source: Internet
Author: User
After the Problem description is entered, the three characters are output in ascending order of the ASCII code of each character. Input There are multiple groups of input data, each group occupies one rowIt consists of three characters and has no space between them. // Filter the carriage return with % * COutput Output one row of input data for each group, Separated by a space. Printf ("... \ n ");Sample inputqwe ASD zxc sample outpute Q wa d SC x zcode1: # include <stdio. h> int main () {char a, B, c, TMP; while (scanf ("% C % * C", & A, & B, & C )! = EOF )// Use "% * C" (null character, character not stored) to filter out the carriage return{If (A> B) TMP = A, A = B, B = TMP; // comma expression, concise if (a> C) TMP = A, A = C, C = TMP; If (B> C) TMP = B, B = C, C = TMP; printf ("% C \ n", A, B, c);} return 0;} code2:

# Include <stdio. h>

Int main ()
{
Char A, B, C, TMP;
While (A = getchar ())! = EOF)
{
B = getchar ();
C = getchar ();
Getchar (); // use getchar () to filter out the carriage return after entering C
If (A> B)
{
TMP =;
A = B;
B = TMP;
}
If (A> C)
{
TMP =;
A = C;
C = TMP;
}
If (B> C)
{
TMP = B;
B = C;
C = TMP;
}
Printf ("% C \ n", A, B, C );
}
Return 0;
}

Use % * C to filter out carriage return and sort by ASCII 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.