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

Envío 4337

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

  • Autor: saris123
  • Fecha: 2021-06-10 00:53:33 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.121 s 13 KBi
#2
Correcto
0.147 s 12 KBi
#3
Correcto
0.139 s 34 KBi
#4
Correcto
0.126 s 13 KBi
#5
Correcto
0.157 s 12 KBi
#6
Correcto
0.163 s 12 KBi
#7
Correcto
0.2 s 12 KBi
#8
Correcto
0.139 s 13 KBi
#9
Correcto
0.17 s 34 KBi
#10
Correcto
0.146 s 14 KBi
Puntos totales: 100 / 100

Código

import java.util.*;

public class Main {
    public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
        int numberArray[] = new int[N];
        for(int i = 0; i < N; i++)
        {
            numberArray[i] = sc.nextInt();
        }
        
        int C = sc.nextInt();
        int queryArray[] = new int[C];
        for(int i = 0; i < C; i++)
        {
            queryArray[i] = sc.nextInt();
        }
        sc.close();

        for(int i = 0; i < C; i++)
        {
            System.out.println(CountGreaterThan(numberArray, queryArray[i]));
        }
    }

     private static int CountGreaterThan(int[] array, int numberToCompare) {
    	int counter = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > numberToCompare)
                counter = counter + 1 ;
        }
        return counter;
    }
}