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

Envío 5032

Problema 0xdd - Ordenar un arreglo pequeño

  • Autor: cams2692
  • Fecha: 2021-10-07 15:14:15 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 4 KBi
#2
Correcto
0.004 s 3 KBi
#3
Correcto
0.004 s 3 KBi
#4
Correcto
0.003 s 3 KBi
#5
Correcto
0.005 s 3 KBi
#6
Correcto
0.004 s 4 KBi
#7
Correcto
0.004 s 3 KBi
#8
Correcto
0.004 s 4 KBi
#9
Correcto
0.004 s 3 KBi
#10
Correcto
0.004 s 4 KBi
#11
Correcto
0.071 s 11 KBi
#12
Correcto
0.058 s 7 KBi
#13
Correcto
0.074 s 4 KBi
#14
Correcto
0.161 s 4 KBi
#15
Correcto
0.136 s 4 KBi
#16
Correcto
0.084 s 3 KBi
#17
Correcto
0.094 s 4 KBi
#18
Correcto
0.073 s 4 KBi
#19
Correcto
0.122 s 4 KBi
#20
Correcto
0.114 s 4 KBi
Puntos totales: 100 / 100

Código

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, _ := reader.ReadString('\n')
	n = strings.ReplaceAll(n, "\n", "")

	numbersS, _ := reader.ReadString('\n')
	numbersS = strings.ReplaceAll(numbersS, "\n", "")
	numbers := strings.Split(numbersS, " ")

	for i := 0; i < len(numbers)-1; i++ {

		for j := 0; j < len(numbers)-1; j++ {
			number, _ := strconv.ParseInt(numbers[j], 10, 64)
			indexNumber, _ := strconv.ParseInt(numbers[j+1], 10, 64)
			if indexNumber < number {
				numberAux := numbers[j]
				numbers[j] = numbers[j+1]
				numbers[j+1] = numberAux
			}
		}

	}
	fmt.Println(strings.Join(numbers, " "))
}