#include <stdio.h>
const char *ft_strstr(const char *str, const char *to_find) {
if (str[0] == 0 && to_find[0] == 0) return str;
for (int i = 0; str[i]; i++) {
int j;
for (j = 0; to_find[j] && str[i + j] && to_find[j] == str[i + j]; j++);
if (to_find[j] == 0) return &(str[i]);
}
return NULL;
}
int main(void) {
printf("1: %s\n", ft_strstr
("Testando", "st")); printf("2: %s\n", ft_strstr
("O rato roeu a roupa do rei de Roma", "ro")); printf("3: %s\n", ft_strstr
("Nao vai achar", "vai nada")); printf("4: %s\n", ft_strstr
("Vai achar no fim", "fim")); printf("5: %s\n", ft_strstr
("Logo no inicio vai ser encontrado", "Logo no inicio")); printf("6: %s\n", ft_strstr
("Nao vai procurar nada", "")); printf("7: %s\n", ft_strstr
("", "Vai procurar em lugar nenhum")); printf("8: %s\n", ft_strstr
("", "")); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpjb25zdCBjaGFyICpmdF9zdHJzdHIoY29uc3QgY2hhciAqc3RyLCBjb25zdCBjaGFyICp0b19maW5kKSB7CiAgICBpZiAoc3RyWzBdID09IDAgJiYgdG9fZmluZFswXSA9PSAwKSByZXR1cm4gc3RyOwogICAgZm9yIChpbnQgaSA9IDA7IHN0cltpXTsgaSsrKSB7CiAgICAgICAgaW50IGo7CiAgICAgICAgZm9yIChqID0gMDsgdG9fZmluZFtqXSAmJiBzdHJbaSArIGpdICYmIHRvX2ZpbmRbal0gPT0gc3RyW2kgKyBqXTsgaisrKTsKICAgICAgICBpZiAodG9fZmluZFtqXSA9PSAwKSByZXR1cm4gJihzdHJbaV0pOwogICAgfQogICAgcmV0dXJuIE5VTEw7Cn0KCmludCBtYWluKHZvaWQpIHsKICAgIHByaW50ZigiMTogJXNcbiIsIGZ0X3N0cnN0cigiVGVzdGFuZG8iLCAic3QiKSk7CiAgICBwcmludGYoIjI6ICVzXG4iLCBmdF9zdHJzdHIoIk8gcmF0byByb2V1IGEgcm91cGEgZG8gcmVpIGRlIFJvbWEiLCAicm8iKSk7C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