Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int f(char str[80], char sm[10]) {
  5.     int c = 0;
  6.  
  7.     for(int i = 0; i < strlen(str); i++) {
  8.         int j;
  9.         for(j = 0; sm[j] == str[i + j]; j++) {}
  10.  
  11.         if(j == strlen(sm)) {
  12.             c++;
  13.         }
  14.     }
  15.  
  16.     return c;
  17. }
  18.  
  19. int main() {
  20.     int N = 80, M = 10;
  21.     char s1[N], s2[N], sm[M];
  22.  
  23.     gets(s1);
  24.     gets(s2);
  25.     gets(sm);
  26.  
  27.     int s1_c = f(s1, sm), s2_c = f(s2, sm);
  28.  
  29.     printf("%s\n%s\n", s1, s2);
  30.     printf("dans s1 - %d fois", s1_c);
  31.     printf("dans s2 - %d fois", s2_c);
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement