Advertisement
Josif_tepe

Untitled

Jan 21st, 2024
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 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.     int n;
  26.     scanf("%d", &n);
  27.     int niza[n];
  28.     for(int i = 0; i < n; i++) {
  29.         scanf("%d", &niza[i]);
  30.     }
  31.     int h;
  32.     scanf("%d", &h);
  33.  
  34.     if(h > n) {
  35.         printf("Ne validno h\n");
  36.         return 0;
  37.     }
  38.     for(int i = 0; i < n; i++) {
  39.         if(i + h < n) {
  40.             int ok = -1;
  41.             for(int j = i; j < i + h; j++) {
  42.                 if(niza[j] == h) {
  43.                     ok = 1;
  44.                     break;
  45.                 }
  46.             }
  47.             if(ok == 1) {
  48.                 for(int j = i; j < i + h; j++) {
  49.                     printf("%d ", niza[j]);
  50.                 }
  51.                 printf("\n");
  52.             }
  53.         }
  54.     }
  55. }
  56.  
  57. /*
  58. 11
  59. 4  15  1  42  52  5  39  2  18  87  91
  60. 5
  61. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement