Doubt searching for sub string, inside a string

0

I've done everything the question asked but I'm taking 70% error.

Issue Link

My code

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char** argv)
{
   char nome[10000], zelda[6] = "zelda", *ponteiro;
   ponteiro = NULL;
   int i;
   getchar();
   scanf("%[^\n]", nome);
   for(i=0;i<strlen(nome);i++)
   {
      nome[i]=tolower(nome[i]);  //convertendo tudo para minusculo
   }
   ponteiro = strstr(nome, zelda);
   if(ponteiro)
   {
      printf("Link Bolado\n");
      ponteiro = NULL;
   }
   else
   {
      printf("Link Tranquilo\n");
      ponteiro = NULL;
   }

    return 0;
}
    
asked by anonymous 03.02.2018 / 23:37

1 answer

1

I see two problems: the first is the size of the array you defined as:

char name [10000]

When the question says that the input can be S (1 ≤ | S | ≤ 10 ^ 5), that is, a string of size 1 to 100,000 (100,000), as the strings in C need the character \ 0 at the end of the array, then you should define your array like this:

char name [100001]; / * maximum size one hundred thousand and one * /

The other problem is getchar () before scanf (), it is not necessary because you always remove the first character of the entry causing an entry that starts with "zelda" to be "elda" and making the answer "Link Tranquilo" when in fact it is "Bolado Link".

    
06.02.2018 / 04:50