summaryrefslogtreecommitdiffstats
path: root/šola/aps1
diff options
context:
space:
mode:
Diffstat (limited to 'šola/aps1')
-rw-r--r--šola/aps1/dn/zlivanje/in.txt26
-rw-r--r--šola/aps1/dn/zlivanje/out.txt1
-rw-r--r--šola/aps1/dn/zlivanje/resitev.cpp39
3 files changed, 66 insertions, 0 deletions
diff --git a/šola/aps1/dn/zlivanje/in.txt b/šola/aps1/dn/zlivanje/in.txt
new file mode 100644
index 0000000..eaca3bf
--- /dev/null
+++ b/šola/aps1/dn/zlivanje/in.txt
@@ -0,0 +1,26 @@
+25 3 2
+13
+18
+7
+8
+17
+3
+16
+9
+10
+11
+11
+0
+2
+19
+14
+5
+6
+15
+4
+5
+12
+3
+18
+1
+3
diff --git a/šola/aps1/dn/zlivanje/out.txt b/šola/aps1/dn/zlivanje/out.txt
new file mode 100644
index 0000000..6def2f9
--- /dev/null
+++ b/šola/aps1/dn/zlivanje/out.txt
@@ -0,0 +1 @@
+0 2 3 3 4 5 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 18 19 1 3
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");
+}