█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6901

Problema 0xdd - Ordenar un arreglo pequeño

  • Autor: Aaron Zuñiga
  • Fecha: 2023-02-27 00:57:37 UTC (Hace alrededor de 1 año)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.111 s 13 KBi
#2
Correcto
0.115 s 13 KBi
#3
Correcto
0.087 s 17 KBi
#4
Correcto
0.085 s 16 KBi
#5
Correcto
0.081 s 17 KBi
#6
Correcto
0.139 s 13 KBi
#7
Correcto
0.139 s 13 KBi
#8
Correcto
0.118 s 13 KBi
#9
Correcto
0.105 s 13 KBi
#10
Correcto
0.116 s 13 KBi
#11
Correcto
0.147 s 21 KBi
#12
Correcto
0.18 s 16 KBi
#13
Correcto
0.311 s 17 KBi
#14
Correcto
0.212 s 18 KBi
#15
Correcto
0.241 s 18 KBi
#16
Correcto
0.158 s 15 KBi
#17
Correcto
0.212 s 17 KBi
#18
Correcto
0.165 s 21 KBi
#19
Correcto
0.248 s 17 KBi
#20
Correcto
0.324 s 17 KBi
Puntos totales: 100 / 100

Código

import java.util.Scanner;
class Main
{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        boolean change = true;
        
        if(n == 1){
            System.out.print(sc.nextInt());
            return;
        }
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        for(int i = 0; i < a.length - 1; i++){
            change = true;
            for(int j = 0; j < a.length - i - 1; j++){
                if(a[j] > a[j+1]){
                    int temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                    change = false;
                }
            }
            if(change == true || i == a.length - 2){
                for(int k : a){
                    System.out.print(k+" ");
                }
                break;
            }
        }
    }
}