Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #ifndef DEBUG
- #define DEBUG(...)printf(__VA_ARGS__)
- #endif
- int main() {
- int n, max_red = 1, max_stup = 1;// max_red/_stup su trenutni maksimalan red i stupac
- char **ans;
- //malloc za redove
- ans = malloc(max_red * sizeof(char *));
- for (int i = 0; i < max_red; ++i)
- {
- ans[i] = malloc(max_stup * sizeof(char)); // malloc za stupce
- memset(ans[i], ' ', max_stup * sizeof(char)); // punjenje tablice praznim pozicijama
- }
- scanf("%d", &n);
- for (int i = 0; i < n; ++i)
- {
- int r, s;
- char c;
- scanf(" %d %d %c", &r, &s, &c);
- r++;
- s++;
- //zasto inkrementacija ????
- if (r > max_red) // ako je skenirani red veci od trenutnog makismalnog
- // prosiri polje ans za toliko redova
- {
- ans = realloc(ans, r * sizeof(char *));
- for (int j = max_red; j < r; ++j)
- {
- ans[j] = malloc(max_stup * sizeof(char));//jer pri povecanju polja , nove ćelije u vec
- //postojecim stupcima nemaju alocirano za sebe nista, zato moramo opet alocirat stupce
- //ovaj put samo za te "nove" ćelije
- memset(ans[j], ' ', max_stup * sizeof(char)); // i naravno setat ih da sadrze razmak
- }
- max_red = r;
- }
- if (s > max_stup)// ako je skenirani stupac veci od trenutnog maximalnog
- //prosiri polje ans za toliko stupaca
- {
- for (int j = 0; j < max_red; ++j)
- {
- ans[j] = realloc(ans[j], s * sizeof(char));
- memset(ans[j] + max_stup, ' ', (s - max_stup) * sizeof(char));
- // s - max_stup = onoliko koliko je prosireno, tj. setaj samo one koji su dodani ekstra
- //jer su ovi na pocetku vec setani
- //sto znaci ans[j] + max_stup ??????
- }
- max_stup = s;
- }
- ans[--r][--s] = c; // postavi znak na zadanu poziciju u polju
- //zasto dekrementirati ??
- }
- //ispis
- for (int i = 0; i < max_red; ++i)
- {
- for (int j = 0; j < max_stup; ++j)
- {
- printf("%c", ans[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement