URI-1042 Solve

Simple Sort

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed.

Input

The input contains three integer numbers.

Output

Present the output as requested above.
Input SampleOutput Sample
7 21 -14-14
7
21

7
21
-14
-14 21 7-14
7
21

-14
21
7
Problem link: [URI-1042##link##]

Solution

  • [tab]
    • C
      • #include <stdio.h>
        
        void printInOrder(int a, int b, int c)
        {
            int min, mid, max;
            if(a < b && a < c){
                min = a;
                if(b < c){
                    mid = b;
                    max = c;
                }else{
                    mid = c;
                    max = b;
                }
            }else if(b < a && b < c){
                min = b;
                if(a < c){
                    mid = a;
                    max = c;
                }else{
                    mid = c;
                    max = a;
                }
            }else{
                min = c;
                if(a < b){
                    mid = a;
                    max = b;
                }else{
                    mid = b;
                    max = a;
                }
            }
            printf("%d\n%d\n%d\n", min, mid, max);
        
        }
        
        int main()
        {
            int a, b, c;
        
            scanf("%d %d %d", &a, &b, &c);
        
            printInOrder(a, b, c);
            printf("\n%d\n%d\n%d\n", a, b, c);
        
            return 0;
        }
    • C++
      • #include <iostream>
        using namespace std;
        
        void printInOrder(int a, int b, int c)
        {
            int min, mid, max;
            if(a < b && a < c){
                min = a;
                if(b < c){
                    mid = b;
                    max = c;
                }else{
                    mid = c;
                    max = b;
                }
            }else if(b < a && b < c){
                min = b;
                if(a < c){
                    mid = a;
                    max = c;
                }else{
                    mid = c;
                    max = a;
                }
            }else{
                min = c;
                if(a < b){
                    mid = a;
                    max = b;
                }else{
                    mid = b;
                    max = a;
                }
            }
        
            cout << min << endl << mid << endl << max << endl << endl;
                
        }
        
        int main()
        {
            int a, b, c;
        
            cin >> a >> b >> c;
        
            printInOrder(a, b, c);
        
            cout << a << endl << b << endl << c << endl;
        
            return 0;
        }
3/Technology/post-list
Name

Codeforces,53,Problem Solve,90,Programming Tricks,1,URI,37,
ltr
item
DorHubs: URI-1042 Solve
URI-1042 Solve
DorHubs
https://dorhubs.blogspot.com/2019/09/uri-1042-solve.html
https://dorhubs.blogspot.com/
https://dorhubs.blogspot.com/
https://dorhubs.blogspot.com/2019/09/uri-1042-solve.html
true
9087637800571592252
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy