Riposati

Comparação de Substring

Oct 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. int main() {
  5.     char s1[55], s2[55];
  6.     int len1, len2, maior, qtd, y, x, z;
  7.  
  8.     memset(s1, '\0', 55);
  9.     memset(s2, '\0', 55);
  10.  
  11.     while( gets(s1) != NULL ) {
  12.         gets(s2);
  13.         len1 = strlen(s1);
  14.         len2 = strlen(s2);
  15.         maior = 0;
  16.         for(x = 0; x < len1; x++) {
  17.             z = x;
  18.             qtd = 0;
  19.             for(y = 0; y < len2 && z < len1; y++) {
  20.                 if(s1[z] == s2[y]) {
  21.                     qtd++;
  22.                     if(qtd > maior) {
  23.                         maior = qtd;
  24.         }
  25.                     z++;
  26.                 } else {
  27.                     if(qtd > maior) {
  28.                         maior = qtd;
  29.         }
  30.                     qtd = 0;
  31.                     z = x;
  32.                 }
  33.             }
  34.         }
  35.         printf("%d\n", maior);      
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment