URI 1042 problem solution

URI OJ Solution 1042 Simple Sort – Solution in C, C++, Java, Python and C#

Online Judge: URI Online Judge

Problem Name: Simple Sort

Problem Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1042

URI 1042 solution in C language:

#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;
}

 

URI 1042 solution in C++ language:

#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;
}

 

 

URI 1042 solution in JAVA language:

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");
    }
}

 

 

URI 1042 solution in Python language:

# -*- 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

 

Explanation: Check this simple sort solution in different language of URI online judge