Algorithm


Problem Name: beecrowd | 1040
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1042

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 Sample Output Sample

7 21 -14

-14
7
21

7
21
-14

 

-14 21 7

-14
7
21

-14
21
7

Code Examples

#1 Code Example with C Programming

Code - C Programming


#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;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 21 -14

Output

x
+
cmd
-14 7 21 7 21 -14

#2 Code Example with C++ Programming

Code - C++ Programming


#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;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
-14 21 7

Output

x
+
cmd
-14 7 21 -14 21 7

#3 Code Example with Java Programming

Code - Java Programming


import java.io.IOException;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
      int X, Y, Z, min1, min2 = 0, min3 = 0;
      Scanner input = new Scanner(System.in);
      X = input.nextInt();
      Y = input.nextInt();
      Z = input.nextInt();
      min1 = Math.min(X, Math.min(Y, Z));
      if (min1 == X) {
         min2 =Math.min(Y, Z);
         min3 =Math.max(Y, Z);
      }
     if (min1 == Y) {
       min2 =Math.min(X, Z);
       min3 =Math.max(X, Z);
     }
     if (min1 == Z) {
       min2 = Math.min(X, Y);
       min3 = Math.max(X, Y);
     }
     System.out.print(min1+"\n"+min2+"\n"+min3+"\n\n");
     System.out.print(X+"\n"+Y+"\n"+Z+"\n");
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 21 -14

Output

x
+
cmd
-14 7 21 7 21 -14

#4 Code Example with Python Programming

Code - Python Programming


# -*- coding: utf-8 -*-
#Pegando os números do teclado
entrada = raw_input().split()
#Transformando eles em inteiro
a = int(entrada[0])
b = int(entrada[1])
c = int(entrada[2])
#Colocando todos em uma lista
lista = [a,b,c]
#Ordenando a lista
lista.sort()
#Mostrando os numeros ordenados
print lista[0]
print lista[1]
print lista[2]
print ""
#Mostrando os números como foram digitados
print a
print b
print c
Copy The Code & Try With Live Editor

Input

x
+
cmd
-14 21 7

Output

x
+
cmd
-14 7 21 -14 21 7
Advertisements

Demonstration


Previous
#1041 Beecrowd Online Judge Solution 1041 Coordinates of a Point Solution in C, C++, Java, Python and C#
Next
#1043 Beecrowd Online Judge Solution 1043 Triangle- Solution in C, C++, Java, Python and C#