summaryrefslogtreecommitdiffstats
path: root/šola/aps1/dn/zlivanje/resitev.cpp
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-11-03 17:20:41 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-11-03 17:20:41 +0100
commitaf2a5545638a8b88638c1561b319b05bbde35b2f (patch)
treef2024dfc75f336e99d7b3620afd15cc176b8d5ca /šola/aps1/dn/zlivanje/resitev.cpp
parentaps1dn1: osvetlitev (diff)
downloadr-af2a5545638a8b88638c1561b319b05bbde35b2f.tar
r-af2a5545638a8b88638c1561b319b05bbde35b2f.tar.gz
r-af2a5545638a8b88638c1561b319b05bbde35b2f.tar.bz2
r-af2a5545638a8b88638c1561b319b05bbde35b2f.tar.lz
r-af2a5545638a8b88638c1561b319b05bbde35b2f.tar.xz
r-af2a5545638a8b88638c1561b319b05bbde35b2f.tar.zst
r-af2a5545638a8b88638c1561b319b05bbde35b2f.zip
Diffstat (limited to '')
-rw-r--r--šola/aps1/dn/zlivanje/resitev.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/šola/aps1/dn/zlivanje/resitev.cpp b/šola/aps1/dn/zlivanje/resitev.cpp
new file mode 100644
index 0000000..8926019
--- /dev/null
+++ b/šola/aps1/dn/zlivanje/resitev.cpp
@@ -0,0 +1,39 @@
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+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");
+}