Advertisement
Josif_tepe

Untitled

Jun 9th, 2024
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5.  
  6. int funkcija(int *niza, int n) {
  7.     for(int i = 0; i < n; i++) {
  8.         if(niza[i] <= 0) {
  9.             return -1;
  10.         }
  11.     }
  12.     for(int i = 0; i < n; i++) {
  13.         int brojac = 0;
  14.         for(int j = 0; j < n; j++) {
  15.             if(niza[i] == niza[j]) {
  16.                 brojac++;
  17.             }
  18.         }
  19.         if(niza[i] != brojac) {
  20.             return 0;
  21.         }
  22.     }
  23.     return 1;
  24. }
  25. int main(int argc, char * argv[]) {
  26.     int n;
  27.     scanf("%d", &n);
  28.  
  29.     int niza[n];
  30.     for(int i = 0; i < n; i++) {
  31.         scanf("%d", &niza[i]);
  32.     }
  33.     int result = funkcija(niza, n);
  34.     printf("%d\n", result);
  35.    
  36. }
  37.  
  38.  
  39. /*
  40. 10
  41. 2 4 2 4 3 3 3 4 1 4
  42.  
  43. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement