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

Envío 4702

Problema 0x62 - Contar elementos mayores a X en un arreglo pequeño

  • Autor: cams2692
  • Fecha: 2021-08-09 21:07:08 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 5 KBi
#2
Correcto
0.004 s 6 KBi
#3
Correcto
0.004 s 8 KBi
#4
Correcto
0.004 s 9 KBi
#5
Correcto
0.005 s 14 KBi
#6
Correcto
0.004 s 5 KBi
#7
Correcto
0.005 s 8 KBi
#8
Correcto
0.005 s 7 KBi
#9
Correcto
0.004 s 7 KBi
#10
Correcto
0.004 s 11 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", "")
	nArray, _ := reader.ReadString('\n')
	nArray = strings.ReplaceAll(nArray, "\n", "")
	numbers := strings.Split(nArray, " ")
	c, _ := reader.ReadString('\n')
	c = strings.ReplaceAll(c, "\n", "")
	cNumber, _ := strconv.ParseInt(c, 10, 64)
	numbersCases := make([]int64, 0)
	numbersSolution := make([]int64, 0)
	for i := 0; i < int(cNumber); i++ {
		caseLine, _ := reader.ReadString('\n')
		caseLine = strings.ReplaceAll(caseLine, "\n", "")
		caseNumber, _ := strconv.ParseInt(caseLine, 10, 64)
		numbersCases = append(numbersCases, caseNumber)
		numbersSolution = append(numbersSolution, 0)
	}

	for i := 0; i < len(numbers); i++ {
		number, _ := strconv.ParseInt(numbers[i], 10, 64)
		for j := 0; j < len(numbersCases); j++ {
			if number > numbersCases[j] {
				numbersSolution[j] = numbersSolution[j] + 1
			}
		}
	}

	for i := 0; i < len(numbersSolution); i++ {
		fmt.Println(numbersSolution[i])
	}

}