I am asking the question Low Frequency I have already tested the Udebug cases but the judge online only returns me Runtime error, by what I know when this happens and when it tries to use memory location that was not allocated, however I have allocated more than the requested question and even then the problem continues
My code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
double resultado(char *frase);
int main(int argc, char** argv)
{
int teste, tam, cont, cont2, indice, i;
char frase[900], presenca[900];
char *ptr_1, *ptr_2;
double vetor[900];
char **nomes = malloc(sizeof(char) * 300);
char **presencas = malloc(sizeof(char) * 300);
for(i = 0; i < 300; i++)
{
nomes[i] = malloc(sizeof(char) * 900);
}
for(i = 0; i < 300; i++)
{
presencas[i] = malloc(sizeof(char) * 900);
}
scanf("%d", &teste);
while(teste--)
{
cont2 = cont = 0;
getchar();
scanf("%d", &tam);
scanf(" %[^\n]", frase);
scanf(" %[^\n]", presenca);
ptr_1 = strtok(frase, " ");
while(ptr_1 != NULL)
{
strcpy(nomes[cont], ptr_1);
cont++;
ptr_1 = strtok(NULL, " ");
}
ptr_2 = strtok(presenca, " ");
while(ptr_2 != NULL)
{
strcpy(presencas[cont2], ptr_2);
cont2++;
ptr_2 = strtok(NULL, " ");
}
for(indice = 0; indice < tam ; indice++)
{
vetor[indice] = resultado(presencas[indice]);
}
for(i = 0; i < tam; i++)
{
if(vetor[i] <= 75.0)
{
printf("%s ", nomes[i]);
}
}
memset(vetor, 0, sizeof(vetor));
printf("\n");
}
for(i = 0; i < 300; i++)
{
free(nomes[i]);
}
free(nomes);
for(i = 0; i < 300; i++)
{
free(presencas);
}
free(presencas);
return 0;
}
double resultado(char *frase)
{
int i, tam = strlen(frase);
double cont = 0;
for(i = 0; i < tam; i++)
{
if(frase[i] == 'M' || frase[i] == 'P')
{
cont++;
}
}
return (cont * 100) / tam;
}