From e1ca97ded1258fea7c5cef33b35a318c72b41836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Fri, 27 Jan 2023 15:55:37 +0100 Subject: =?UTF-8?q?rtk=20=C5=A1olsko=202023?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "inf/rtk\305\241/2.c" | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "inf/rtk\305\241/2.c" (limited to 'inf/rtkš/2.c') diff --git "a/inf/rtk\305\241/2.c" "b/inf/rtk\305\241/2.c" new file mode 100644 index 0000000..63f0953 --- /dev/null +++ "b/inf/rtk\305\241/2.c" @@ -0,0 +1,58 @@ +#include +#include +#include +#define MIN(a,b) ((a) > (b) ? (b) : (a)) +#define MAX(a,b) ((a) < (b) ? (b) : (a)) +struct stolpec { + int položaj; + int višina; + int izmeril; +}; +int primerjaj_stolpca (const void * a, const void * b) { + const struct stolpec * c = (const struct stolpec *) a; + const struct stolpec * d = (const struct stolpec *) b; + return d->višina - c->višina; +} +void natisni (int n, const struct stolpec * s) { + for (int i = 0; i < n; i++) { + printf("%d: ", s[i].položaj); + for (int j = 0; j < s[i].višina; j++) + printf("@"); + printf("\n"); + } +} +int voda (int n, struct stolpec * s) { + struct stolpec razv[n]; + memcpy(razv, s, n*sizeof *s); + qsort(razv, n, sizeof *s, primerjaj_stolpca); + natisni(n, s); + printf("---------\n"); + natisni(n, razv); + int povr = 0; + for (int i = 0; i < n-1; i++) { + int max_pol = MAX(razv[i].položaj, razv[i+1].položaj); + int min_pol = MIN(razv[i].položaj, razv[i+1].položaj); + if (max_pol - min_pol > 1) { + printf("med stoplcema z indeksoma %d in %d\n", min_pol, max_pol); + for (int j = min_pol+1; j < max_pol; j++) { + if (s[j].izmeril) + continue; + int tapovr = razv[i+1].višina - s[j].višina; + if (tapovr > 0) + povr += tapovr; + s[j].izmeril++; + printf("izmeril stoplec indeks %d - povr je %d ... min_viš je %d, s[j].višina je %d\n", j, povr, razv[i+1].višina, s[j].višina); + } + } + } + return povr; +} +int main (int argc, char ** argv) { + int n = argc-1; + struct stolpec * stolpci = calloc(n, sizeof *stolpci); + for (int i = 0; i < n; i++) { + stolpci[i].položaj = i; + stolpci[i].višina = atoi(argv[i+1]); + } + return voda(n, stolpci); +} -- cgit v1.2.3