Advertisement
Josif_tepe

Untitled

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