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
- char **nacrtaj(int *p, int n, int h) {
- // alocirati memoriju za 2d polje koje treba vratiti
- char ** ans = malloc((h * HEIGHT) * sizeof(char *));
- for (int i = 0; i < h * HEIGHT; ++i)
- {
- ans[i] = malloc((n*(WIDTH + GAP) - GAP) * sizeof(char)); // ###.. -> width+gap - 1 gap na kraju da nemam .. iza zadnjeg widtha
- memset(ans[i], '.', (n*(WIDTH + GAP) - GAP) * sizeof(char));
- }
- // ucrtati ekvilajzer u polje
- for (int i = 0; i < n; ++i)
- {
- for (int j = (h - p[i]) * HEIGHT; j < h * HEIGHT; ++j)//???? int j = ???????
- {
- for (int w = 0; w < WIDTH; ++w)
- {
- ans[j][i * (WIDTH+GAP) + w] = '#'; // ???? ovo u stupac dijelu ? ??
- }
- }
- }
- return ans;
- }
- 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
- free(p);
- for (int i = 0; i < h*HEIGHT; ++i)
- {
- free(ans[i]);
- }
- free(ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement