Advertisement
lukicdarkoo

Provjeravanje podniza

Dec 11th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. //Provjeriti da li je drugi unijeti niz podniz prvog
  2.  
  3. #include <stdio.h>
  4. #define MAX_SIZE 100
  5.  
  6. int main()
  7. {
  8.     int firstArray[MAX_SIZE], firstN;
  9.     int secondArray[MAX_SIZE], secondN;
  10.  
  11.     int i;
  12.  
  13.     scanf("%i", &firstN);
  14.     for (i = 0; i < firstN; i++)
  15.         scanf("%i", &firstArray[i]);
  16.  
  17.     scanf("%i", &secondN);
  18.     for (i = 0; i < secondN; i++)
  19.         scanf("%i", &secondArray[i]);
  20.  
  21.     for (i = 0; i <= firstN - secondN; i++)
  22.         if (isEqualivent(&(firstArray[i]), secondArray, secondN)) {
  23.             printf("1");
  24.             return 0;
  25.         }
  26.  
  27.     printf("0");
  28.  
  29.     return 0;
  30. }
  31.  
  32. int isEqualivent(int firstArray[MAX_SIZE], int secondArray[MAX_SIZE], int length) {
  33.     int i = 0;
  34.     for (; i < length; i++)
  35.         if (firstArray[i] != secondArray[i])
  36.             return 0;
  37.  
  38.     return 1;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement