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

Envío 4238

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

  • Autor: andres0608
  • Fecha: 2021-05-30 01:02:45 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.13 s 12 KBi
#2
Correcto
0.139 s 14 KBi
#3
Correcto
0.13 s 13 KBi
#4
Correcto
0.123 s 13 KBi
#5
Correcto
0.224 s 14 KBi
#6
Correcto
0.237 s 16 KBi
#7
Correcto
0.136 s 12 KBi
#8
Correcto
0.148 s 13 KBi
#9
Correcto
0.291 s 14 KBi
#10
Correcto
0.188 s 14 KBi
Puntos totales: 100 / 100

Código

import java.util.*;
public class Main {

     public static void main(String[] args) throws Exception {
		 
		 String  numero1, numero2,numero3,valor;
		 Scanner numeros = new Scanner(System.in);
		 numero1 = numeros.nextLine();
		 numero2="";
		 numero2 += numeros.nextLine();
		 numero3= numeros.nextLine();
		 String[] numbers = numero2.split(" ");
		 int result;
		 for(int i=0;i < Integer.parseInt(numero3);i++) {
			 valor = numeros.nextLine();
			 result= contar(numbers, Integer.parseInt(valor));
			 System.out.println(result);
		 }
		 numeros.close();  
	 }
	 
	 
	 public static int contar(String[] v, int c) {
         int contador=0;
		 for(int i=0; i < v.length; i++) {
			 if(Integer.parseInt(v[i]) > c) {
				 contador++;
			 }
		 }
		 return contador;
	 }
}