Advertisement
Josif_tepe

Untitled

Jan 21st, 2024
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. void funkcija(char * tekst, char * zbor) {
  7.     int brojac = 0;
  8.     for(int i = 0; i < strlen(tekst); i++) {
  9.         if(tekst[i] == zbor[0]) {
  10.             int ok = 1;
  11.             for(int j = 0; j < strlen(zbor); j++) {
  12.                 if(tekst[i + j] != zbor[j]) {
  13.                     ok = -1;
  14.                     break;
  15.                 }
  16.             }
  17.             if(ok == 1) {
  18.                 brojac++;
  19.             }
  20.         }
  21.     }
  22.     printf("%d\n", brojac);
  23. }
  24. int main(int argc, const char * argv[]) {
  25.     char tekst[1000], zbor[1000];
  26.     fgets(tekst, 500, stdin);
  27.     scanf("%s", zbor);
  28.     funkcija(tekst, zbor);
  29. }
  30.  
  31. /*
  32. 14 12 -6 20 15 -1 10 6 -7 -20
  33. 14, 12, -6, -7, -8, -9, -10, -20
  34. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement