summaryrefslogtreecommitdiffstats
path: root/šola/p1/dn/DN10_63230317.java
blob: 25dc70f0a87b3adc797f97927e6aad559e916b52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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());
	}
}