From af2a5545638a8b88638c1561b319b05bbde35b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 3 Nov 2024 17:20:41 +0100 Subject: aps1dn2: zlivanje --- "\305\241ola/aps1/dn/zlivanje/resitev.cpp" | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "\305\241ola/aps1/dn/zlivanje/resitev.cpp" (limited to 'šola/aps1/dn/zlivanje/resitev.cpp') diff --git "a/\305\241ola/aps1/dn/zlivanje/resitev.cpp" "b/\305\241ola/aps1/dn/zlivanje/resitev.cpp" new file mode 100644 index 0000000..8926019 --- /dev/null +++ "b/\305\241ola/aps1/dn/zlivanje/resitev.cpp" @@ -0,0 +1,39 @@ +#include +#include +#include +#include +int compar_long (const void * a, const void * b) { + if (*(long *)a < *(long *)b) + return -1; + return *(long *)a > *(long *) b; +} +int main (void) { + long N, K, A; + scanf("%ld %ld %ld", &N, &K, &A); + long * d = (long *) malloc(N*sizeof *d); + long čet = 0; + long lastidx = 0; + long long četkončno = 1; + for (long i = 0; i < A && četkončno <= 2000000; i++) // pravzaprav četkončno := K**A, + četkončno *= K; // toda C nima int potence + // fprintf(stderr, "aaaaaaaa %ld\n", četkončno); + for (long i = 0; i < N; i++) { + scanf("%ld", d+i); + if (i && d[i-1] > d[i]) + if (++čet >= četkončno) { + qsort(d+lastidx, i-lastidx, sizeof d[0], compar_long); + čet = 0; + lastidx = i; + } + } + qsort(d+lastidx, N-lastidx, sizeof d[0], compar_long); + bool devica = true; + for (long i = 0; i < N; i++) { + if (devica) + devica = false; + else + printf(" "); + printf("%ld", d[i]); + } + printf("\n"); +} -- cgit v1.2.3