Advertisement
Guest User

Untitled

a guest
May 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  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. //p su svi ekualizeri, n je koliko ih ima i h je najveci
  19. char **nacrtaj(int *p, int n, int h) {
  20. // alocirati memoriju za 2d polje koje treba vratiti
  21. char **eq;
  22. int broj;
  23. eq = malloc(sizeof(char *) * (h*HEIGHT));
  24.  
  25. for(int i = 0; i < h*HEIGHT; i++){
  26. eq[i] = malloc(sizeof(char) * (n*3)+(2*(n-1)));
  27. memset(eq[i], '.', (sizeof(char) * (n*3)+(2*(n-1))));
  28. }
  29.  
  30.  
  31. // ucrtati ekvilajzer u polje
  32. int k = 0, z = 0;
  33. while(n > 0){
  34. broj = (h - (*(p+k))) * HEIGHT;
  35.  
  36. for(int i = broj; broj < h*HEIGHT; i++){
  37. for(int j = 0+z; j < WIDTH + z; j++){
  38. eq[i][j] = '#';
  39. }
  40. }
  41. z += 6;
  42. n--;
  43. k++;
  44. }
  45.  
  46. return eq;
  47. }
  48.  
  49. void ispisi(char **ans, int n, int h) {
  50. for (int i = 0; i < h*HEIGHT; ++i) {
  51. for (int j = 0; j < n*(WIDTH+GAP)-GAP; ++j) {
  52. printf("%c", ans[i][j]);
  53. }
  54. printf("\n");
  55. }
  56. }
  57.  
  58. int main() {
  59. int n, *p, h = 0;
  60. scanf("%d", &n);
  61. p = malloc(n*sizeof(int));
  62. for (int i = 0; i < n; ++i) {
  63. scanf("%d", p+i);
  64. h = p[i]>h ? p[i] : h;
  65. }
  66.  
  67. char **ans = nacrtaj(p, n, h);
  68. ispisi(ans, n, h);
  69. // osloboditi cjelokupnu alociranu memoriju
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement