SHARE
TWEET

Grafički Ekvilajzer

KgCro May 29th, 2020 540 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7. #ifndef DEBUG
  8. #define DEBUG(...) printf(__VA_ARGS__)
  9. #endif
  10.  
  11.  
  12. // širina stupca
  13. #define WIDTH 3
  14. // jedinična visina stupca
  15. #define HEIGHT 2
  16. // razmak između stupaca
  17. #define GAP 2
  18.  
  19.  
  20. char **nacrtaj(int *p, int n, int h) {
  21.   // alocirati memoriju za 2d polje koje treba vratiti
  22.   char ** ans = malloc((h * HEIGHT) * sizeof(char *));
  23.   for (int i = 0; i < h * HEIGHT; ++i)
  24.   {
  25.     ans[i] = malloc((n*(WIDTH + GAP) - GAP) * sizeof(char)); // ###.. -> width+gap - 1 gap na kraju da nemam .. iza zadnjeg widtha
  26.     memset(ans[i], '.', (n*(WIDTH + GAP) - GAP) * sizeof(char));
  27.   }
  28.   // ucrtati ekvilajzer u polje
  29.   for (int i = 0; i < n; ++i)
  30.   {
  31.     for (int j = (h - p[i]) * HEIGHT; j < h * HEIGHT; ++j)//???? int j = ???????
  32.     {
  33.      for (int w = 0; w < WIDTH; ++w)
  34.       {
  35.         ans[j][i * (WIDTH+GAP) + w] = '#';  // ???? ovo u stupac dijelu ? ??
  36.       }
  37.     }
  38.   }
  39.   return ans;
  40. }
  41.  
  42. void ispisi(char **ans, int n, int h) {
  43.   for (int i = 0; i < h*HEIGHT; ++i) {
  44.     for (int j = 0; j < n*(WIDTH+GAP)-GAP; ++j) {
  45.       printf("%c", ans[i][j]);
  46.     }
  47.     printf("\n");
  48.   }
  49. }
  50.  
  51. int main() {
  52.   int n, *p, h = 0;
  53.   scanf("%d", &n);
  54.   p = malloc(n*sizeof(int));
  55.   for (int i = 0; i < n; ++i) {
  56.     scanf("%d", p+i);
  57.     h = p[i]>h ? p[i] : h;
  58.   }
  59.  
  60.   char **ans = nacrtaj(p, n, h);
  61.   ispisi(ans, n, h);
  62.   // osloboditi cjelokupnu alociranu memoriju
  63.  
  64.   free(p);
  65.   for (int i = 0; i < h*HEIGHT; ++i)
  66.   {
  67.     free(ans[i]);
  68.   }
  69.   free(ans);
  70.  
  71.   return 0;
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top