Advertisement
Guest User

Zadanie 1

a guest
Sep 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. main()
  4. {
  5.     int t, n, i, j, poz, min, max, zisk;
  6.     scanf("%d\n", &t);
  7.     while (t > 0)
  8.     {
  9.         scanf("%d ", &n);
  10.         if (n > 0)
  11.         {
  12.             int *ceny = (int *) calloc(n, sizeof(int));
  13.             max = -1; zisk = 0;
  14.  
  15.             for (i = 0; i < n; i++)
  16.             {
  17.                 scanf("%d", &ceny[i]);
  18.             }
  19.  
  20.             for(i = 0; i < n; i++)
  21.             {
  22.                 for(j = i+1; j < n; j++)
  23.                 {
  24.                     if(ceny[i] < ceny[i+j] && ceny[i+1]-ceny[i] > max)
  25.                     {
  26.                         max = ceny[i+1]-ceny[i];
  27.                         poz = j;
  28.                     }
  29.                 }
  30.                 i = poz;
  31.                 zisk += max;
  32.             }
  33.            
  34.             printf("Zisk: %d", zisk);
  35.             free(ceny);
  36.         }
  37.         if(n <= 0)
  38.             printf("n musi byt vacsie ako 0!");
  39.         n = -1; zisk = -1; t -= 1;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement