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

Envío 1129

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

  • Autor: EduardoVega
  • Fecha: 2020-10-11 00:29:33 UTC (Hace alrededor de 4 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#2
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#3
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#4
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#5
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#6
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#7
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.005 s 2 KBi
#8
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
#9
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 5 KBi
#10
Correcto
                      main.c:31:20: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
    printf("%d\n", contador);
            ~~     ^~~~~~~~
            %ld
1 warning generated.

                    
0.004 s 1 KBi
Puntos totales: 100 / 100

Código

#include <stdio.h>
#include <stdlib.h>

int main()
{
  long int size_array = 0, num_consultas = 0, 
  num_arr = 0, contador = 0, consulta = 0, i, j;
  long int *array = NULL;  

  scanf("%li", &size_array);
  array = malloc(sizeof(long int) * size_array);
  if (array == NULL || size_array <= 0)
      return -1;

  for (i = 0; i < size_array; i++)
  {
     scanf("%li", &num_arr);
     array[i] = num_arr; 
  }

  scanf("%li", &num_consultas);

  for (i = 0; i < num_consultas; i++)
  {
    scanf("%li", &consulta);
    for (j = 0; j < size_array; j++)
    {
      if (array[j] > consulta)
          contador++;
    }
    printf("%d\n", contador);
    contador = 0;
  }
  
  free(array);
  return 0;  
}