summaryrefslogtreecommitdiffstats
path: root/šola/p1/dn
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-01-07 17:20:10 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-01-07 17:20:10 +0100
commit52adeb80998ec0c7d7e5229eedc5a5752f9c02cb (patch)
treefb49b68a9535d5904b7a4146becef5b0d65b9523 /šola/p1/dn
parentDN09 (diff)
downloadr-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.tar
r-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.tar.gz
r-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.tar.bz2
r-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.tar.lz
r-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.tar.xz
r-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.tar.zst
r-52adeb80998ec0c7d7e5229eedc5a5752f9c02cb.zip
Diffstat (limited to 'šola/p1/dn')
-rw-r--r--šola/p1/dn/DN10_63230317.java141
1 files changed, 141 insertions, 0 deletions
diff --git a/šola/p1/dn/DN10_63230317.java b/šola/p1/dn/DN10_63230317.java
new file mode 100644
index 0000000..25dc70f
--- /dev/null
+++ b/šola/p1/dn/DN10_63230317.java
@@ -0,0 +1,141 @@
+import java.util.*;
+import java.util.stream.*;
+public class DN10_63230317 {
+ static class Trit implements Comparable<Trit> {
+ int vrednost;
+ public Trit (String s) {
+ vrednost = 3;
+ if (s.equals("da"))
+ vrednost = 0;
+ if (s.equals("ne"))
+ vrednost = 1;
+ if (s.equals("morda"))
+ vrednost = 2;
+ }
+ @Override
+ public String toString () {
+ String s[] = new String[]{"da", "ne", "morda", "nedefinirano"};
+ return s[vrednost];
+ }
+ @Override
+ public int compareTo (Trit o) {
+ return Integer.compare(vrednost, o.vrednost);
+ }
+ }
+ static class Vrednost implements Comparable<Vrednost> {
+ int tip;
+ String niz;
+ Trit trit;
+ int št;
+ public Vrednost (String s) {
+ tip = 2;
+ niz = s;
+ }
+ public Vrednost (Trit t) {
+ tip = 3;
+ trit = t;
+ }
+ public Vrednost (int š) {
+ tip = 1;
+ št = š;
+ }
+ @Override
+ public String toString () {
+ switch (tip) {
+ case 1:
+ return Integer.valueOf(št).toString();
+ case 2:
+ return niz;
+ case 3:
+ return trit.toString();
+ }
+ return null;
+ }
+ @Override
+ public int compareTo (Vrednost o) {
+ if (tip != o.tip)
+ return Integer.compare(tip, o.tip);
+ switch (tip) {
+ case 1:
+ return Integer.compare(št, o.št);
+ case 2:
+ return niz.compareTo(o.niz);
+ case 3:
+ return trit.compareTo(o.trit);
+ }
+ throw new RuntimeException("unreachable");
+ }
+ }
+ static class Vrstica {
+ Vrednost stolpci[];
+ public Vrstica (Vrednost[] s) {
+ stolpci = s;
+ }
+ public Vrstica (int tipi[], String s) {
+ stolpci = new Vrednost[tipi.length];
+ int i = 0;
+ if (s.split(" ").length != tipi.length)
+ throw new RuntimeException("nepravilno število stolpcev. niz je " + s + ", tipov je " + tipi.length);
+ for (String a : s.split(" ")) {
+ switch (tipi[i]) {
+ case 1:
+ stolpci[i++] = new Vrednost(Integer.parseInt(a));
+ continue;
+ case 2:
+ stolpci[i++] = new Vrednost(a);
+ continue;
+ case 3:
+ stolpci[i++] = new Vrednost(new Trit(a));
+ continue;
+ }
+ throw new RuntimeException("nepoznan tip");
+ }
+ }
+ static class Primerjalnik implements Comparator<Vrstica> {
+ int kriteriji[];
+ public Primerjalnik (int[] k) {
+ kriteriji = k;
+ }
+ @Override
+ public int compare (Vrstica a, Vrstica b) {
+ for (int i = 0; i < kriteriji.length; i++) {
+ int r = a.stolpci[(int) Math.abs(kriteriji[i])-1].compareTo(b.stolpci[(int) Math.abs(kriteriji[i])-1]);
+ if (r == 0)
+ continue;
+ return (int) Math.signum(kriteriji[i])*r;
+ }
+ return 0;
+ }
+ }
+ public static Comparator<Vrstica> primerjalnik (int[] kriteriji) {
+ return new Primerjalnik(kriteriji);
+ }
+ @Override
+ public String toString () {
+ return String.join("|", Arrays.asList(stolpci).stream().map(s -> s.toString()).collect(Collectors.toList()));
+ }
+ }
+ public static void main (String[] args) {
+ Scanner sc = new Scanner(System.in);
+ int m = sc.nextInt();
+ int n = sc.nextInt();
+ int tipi[] = new int[n];
+ for (int i = 0; i < n; i++)
+ tipi[i] = sc.nextInt();
+ int k = sc.nextInt();
+ int kriteriji[] = new int[k];
+ for (int i = 0; i < k; i++)
+ kriteriji[i] = sc.nextInt();
+ sc.nextLine(); // preskočimo do konca te vrstice s številkami
+ ArrayList<Vrstica> vrstice = new ArrayList<>();
+ for (int i = 0; i < m; i++) {
+ String besedilo = sc.nextLine();
+ if (besedilo.equals(""))
+ throw new RuntimeException("prazna vrstica na indeksu " + i + " od skupno " + m);
+ vrstice.add(new Vrstica(tipi, besedilo));
+ }
+ Collections.sort(vrstice, Vrstica.primerjalnik(kriteriji));
+ for (Vrstica vrstica : vrstice)
+ System.out.println(vrstica.toString());
+ }
+}