-
Notifications
You must be signed in to change notification settings - Fork 0
/
1237.c
43 lines (35 loc) · 1019 Bytes
/
1237.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <string.h>
int main()
{
char palavra1[51], palavra2[51];
while(scanf("%[^\n]s", palavra1) != EOF)
{
getchar();
scanf("%[^\n]s", palavra2); getchar();
int tamanho1 = strlen(palavra1);
int tamanho2 = strlen(palavra2);
int maior_substring = 0;
for(int i=0; i<tamanho1; i++)
{
for(int j=0; j<tamanho2; j++)
{
int index_j = j;
int index_i = i;
int substring_atual = 0;
while((palavra1[index_i] == palavra2[index_j]) && (index_j< tamanho2) && (index_i < tamanho1))
{
substring_atual++;
index_j++;
index_i++;
}
if(substring_atual > maior_substring)
{
maior_substring = substring_atual;
}
}
}
printf("%d\n", maior_substring);
}
return 0;
}