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

Envío 3758

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

  • Autor: bryancalisto
  • Fecha: 2021-04-13 03:55:20 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.003 s 2 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.007 s 1 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.004 s 1 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.005 s 1 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.004 s 2 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.004 s 1 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.003 s 1 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.006 s 1 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.006 s 1 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.019 s 2 KBi
Puntos totales: 10 / 100

Código

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

int main(void)
{
  int n, c;
  int *resultados;
  int *consultas;
  char *arr;
  int *intArr;
  char *token;
  int tmp;
  int contador = 0;

  scanf("%d *[^\n]", &n);
  arr = (char *)malloc(n * 2);
  intArr = (int *)malloc(n);
  fgets(arr, n * 2, stdin);
  scanf("%d", &c);
  consultas = (int *)malloc(sizeof(int) * c);
  resultados = (int *)malloc(sizeof(int) * c);

  for (int i = 0; i < c; i++)
  {
    scanf("%d", &consultas[i]);
  }

  token = strtok(arr, " ");

  // Armamos arreglo en base a input de usuario
  for (int i = 0; i < n; i++)
  {
    intArr[i] = atoi(token);
    token = strtok(NULL, " ");
  }

  // Ejecutamos cada consulta
  for (int i = 0; i < c; i++)
  {
    tmp = 0;

    for (int j = 0; j < n; j++)
    {
      // printf("intArr[%d]: %d , consultas[%d]: %d\n", j, intArr[j], i, consultas[i]);
      if (intArr[j] > consultas[i])
      {
        tmp++;
      }
    }

    resultados[i] = tmp;
  }

  for (int i = 0; i < c; i++)
  {
    printf("%d\n", resultados[i]);
  }

  free(arr);
  free(intArr);
  free(consultas);
  free(resultados);
  return 0;
}