#include <stdio.h>
int str_conteudo( char str1[], char str2[]) {
int i=0,j,k;
for(i = 0; str1[i] != '\0'; ++i) {
for (j = i,k = 0;str1[j]!= '\0' && str2[k] != '\0' && str1[j] == str2[k]; ++j,k++);
if (str2[k] == '\0'){
return i;
}
}
return -1;
}
int main(int argc, char *argv[]) {
printf("%d\n", str_conteudo
("Frase de teste","de")); printf("%d\n", str_conteudo
("Frase de teste","teste")); printf("%d\n", str_conteudo
("Frase de teste","Frase")); printf("%d\n", str_conteudo
("Frase de teste","cuFra")); printf("%d\n", str_conteudo
("Frase de teste","testem"));
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgc3RyX2NvbnRldWRvKCBjaGFyIHN0cjFbXSwgY2hhciBzdHIyW10pIHsKCWludCBpPTAsaixrOwoJZm9yKGkgPSAwOyBzdHIxW2ldICE9ICdcMCc7ICsraSkgewogICAgICAgIGZvciAoaiA9IGksayA9IDA7c3RyMVtqXSE9ICdcMCcgJiYgc3RyMltrXSAhPSAnXDAnICYmIHN0cjFbal0gPT0gc3RyMltrXTsgKytqLGsrKyk7CiAgICAgICAgaWYgKHN0cjJba10gPT0gJ1wwJyl7CiAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgIH0KCX0KICAgIHJldHVybiAtMTsKfQoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkgewoKICAgIHByaW50ZigiJWRcbiIsIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwiZGUiKSk7CiAgICBwcmludGYoIiVkXG4iLCBzdHJfY29udGV1ZG8gKCJGcmFzZSBkZSB0ZXN0ZSIsInRlc3RlIikpOwogICAgcHJpbnRmKCIlZFxuIiwgc3RyX2NvbnRldWRvICgiRnJhc2UgZGUgdGVzdGUiLCJGcmFzZSIpKTsKICAgIHByaW50ZigiJWRcbiIsIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwiY3VGcmEiKSk7CiAgICBwcmludGYoIiVkXG4iLCBzdHJfY29udGV1ZG8gKCJGcmFzZSBkZSB0ZXN0ZSIsInRlc3RlbSIpKTsKCglyZXR1cm4gMDsKfQo=