Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #ifndef DEBUG
- #define DEBUG(...) printf(__VA_ARGS__)
- #endif
- // širina stupca
- #define WIDTH 3
- // jedinična visina stupca
- #define HEIGHT 2
- // razmak između stupaca
- #define GAP 2
- //p su svi ekualizeri, n je koliko ih ima i h je najveci
- char **nacrtaj(int *p, int n, int h) {
- // alocirati memoriju za 2d polje koje treba vratiti
- char **eq;
- int broj;
- eq = malloc(sizeof(char *) * (h*HEIGHT));
- for(int i = 0; i < h*HEIGHT; i++){
- eq[i] = malloc(sizeof(char) * (n*3)+(2*(n-1)));
- memset(eq[i], '.', (sizeof(char) * (n*3)+(2*(n-1))));
- }
- // ucrtati ekvilajzer u polje
- int k = 0, z = 0;
- while(n > 0){
- broj = (h - (*(p+k))) * HEIGHT;
- for(int i = broj; broj < h*HEIGHT; i++){
- for(int j = 0+z; j < WIDTH + z; j++){
- eq[i][j] = '#';
- }
- }
- z += 6;
- n--;
- k++;
- }
- return eq;
- }
- void ispisi(char **ans, int n, int h) {
- for (int i = 0; i < h*HEIGHT; ++i) {
- for (int j = 0; j < n*(WIDTH+GAP)-GAP; ++j) {
- printf("%c", ans[i][j]);
- }
- printf("\n");
- }
- }
- int main() {
- int n, *p, h = 0;
- scanf("%d", &n);
- p = malloc(n*sizeof(int));
- for (int i = 0; i < n; ++i) {
- scanf("%d", p+i);
- h = p[i]>h ? p[i] : h;
- }
- char **ans = nacrtaj(p, n, h);
- ispisi(ans, n, h);
- // osloboditi cjelokupnu alociranu memoriju
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement