Rezultati

Up. imeNalogaJezikRezultatČas oddaje
scnm1-2018 Birokrati Java 100/100OK 04. okt '18 @ 18:41

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 38,355 MiB 0,000 s OK
#2 9/9 41,922 MiB 0,000 s OK
#3 9/9 39,238 MiB 0,000 s OK
#4 9/9 39,016 MiB 0,000 s OK
#5 9/9 38,816 MiB 0,000 s OK
#6 9/9 49,480 MiB 0,000 s OK
#7 9/9 50,586 MiB 0,000 s OK
#8 9/9 55,332 MiB 0,000 s OK
#9 9/9 49,262 MiB 0,000 s OK
#10 9/9 62,441 MiB 0,186 s OK
#11 10/10 39,316 MiB 0,000 s OK

Ocenjevani program (n1.java):
import java.util.*;
import java.io.*;

class oseba implements Comparable<oseba> {
	String ime;
	pot naslednji;
	boolean najden=false;
	String polnoIme;
	oseba(String a, pot b,String c) {
		ime = a;
		naslednji = b;
		polnoIme=c;
	}

	@Override
	public int compareTo(oseba arg0) {
		return ime.compareTo(arg0.ime);
	}
}

class pot {
	int[] arr;

	pot(ArrayList<Integer> q) {
		arr = new int[q.size()];
		for (int i = 0; i < q.size(); i++) {
			arr[i] = q.get(i);
		}
	}
}

class pots {
	String[] arr;

	pots(String[] q) {
		arr = new String[q.length - 1];
		for (int i = 1; i < q.length; i++) {
			arr[i - 1] = q[i];
		}
	}
}

class node implements Comparable<node> {
	String name;
	ArrayList<oseba> osebe;
	ArrayList<node> otroci;

	node(String ime) {
		name = ime;
		osebe = new ArrayList<oseba>();
		otroci = new ArrayList<node>();
	}

	void add(pots p, int level, pot po,String ime) {
		if (level == p.arr.length - 1) {
			osebe.add(new oseba(p.arr[level], po,ime));
		} else {
			for (node n : otroci) {
				if (n.name.equals(p.arr[level])) {
					n.add(p, level + 1, po,ime);
					return;
				}
			}
			otroci.add(new node(p.arr[level]));
			otroci.get(otroci.size() - 1).add(p, level + 1, po,ime);
		}
	}

	void sort() {
		Collections.sort(osebe);
		Collections.sort(otroci);
		for (node n : otroci) {
			n.sort();
		}
	}

	void prvi(Vector<Integer> a) {
		if (osebe.size() > 0) {
			a.add(0);
		} else {
			if (otroci.size() == 0) {
				System.out.println("Napapka");
			} else {
				a.add(0);
				otroci.get(0).prvi(a);
			}
		}
	}

	oseba get(int[] q, int p) {
		if (q.length - 1 == p) {
			osebe.get(q[p]).najden=true;
			return osebe.get(q[p]);
		} else {
			return otroci.get(q[p]).get(q, p + 1);
		}
	}

	oseba get2(int[] q, int p) {
		try {
			if (q.length - 1 == p) {
				if(osebe.get(q[p]).najden) {
					int t=1/0;
				}
				return osebe.get(q[p]);
			} else {
				return otroci.get(q[p]).get2(q, p + 1);
			}
		} catch (Exception e) {
			//e.printStackTrace();
			return new oseba("A", null,"A");
		}
	}

	@Override
	public int compareTo(node arg0) {
		return name.compareTo(arg0.name);
	}
}

public class n1 {
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("input.in"));
		ArrayList<String> idIme=new ArrayList<String>();
		ArrayList<pots> osebe = new ArrayList<pots>();
		ArrayList<pot> poti = new ArrayList<pot>();
		while (in.ready()) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			String id=st.nextToken();
			idIme.add(id);
			
			String[] left = id.replace('/', 'A').split("A");
			osebe.add(new pots(left));

			String[] text = st.nextToken().replace('.', 'A').split("A");
			ArrayList<Integer> arr = new ArrayList<Integer>();
			for (String s : text) {
				arr.add(Integer.parseInt(s)-1);
			}
			poti.add(new pot(arr));

		}
		node drevo = new node("");
		for (int i = 0; i < osebe.size(); i++) {
			drevo.add(osebe.get(i), 0, poti.get(i),idIme.get(i));
		}
		drevo.sort();
		Vector<Integer> em = new Vector<Integer>();
		drevo.prvi(em);
		int[] p = new int[em.size()];
		for (int i = 0; i < em.size(); i++) {
			p[i] = em.get(i);
		}
		while (true) {
			oseba s = drevo.get(p, 0);
			oseba next = drevo.get2(s.naslednji.arr, 0);
			if (next.ime.equals("A")) {
				System.out.println(s.polnoIme);
				return;
			}else {
				p=s.naslednji.arr;
			}
		}
	}

}