Rezultati

Up. imeNalogaJezikRezultatČas oddaje
pomaranca-2017 Jungle Speed Java 0/100Napaka med izvajanjem / ob izhodu (RTE) 11. maj '17 @ 20:15

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 32,984 MiB 0,000 s OK
#2 9/9 34,875 MiB 0,000 s OK
#3 0/9 33,504 MiB 0,000 s Napačen odgovor
Tvoj izhod:
​1
<<<EOF>>>
Pravilen izhod:
​2
<<<EOF>>>
#4 0/9 36,898 MiB 0,000 s Napačen odgovor
Tvoj izhod:
​2
<<<EOF>>>
Pravilen izhod:
​4
<<<EOF>>>
#5 0/9 29,063 MiB 0,000 s Program je končal z neničelno kodo
Stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 >= 8
	at java.util.Vector.elementAt(Vector.java:474)
	at jungle_speed.main(jungle_speed.java:70)
#6 0/9 23,902 MiB 0,000 s Program je končal z neničelno kodo
Stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 >= 8
	at java.util.Vector.elementAt(Vector.java:474)
	at jungle_speed.main(jungle_speed.java:70)
#7 0/9 34,656 MiB 0,000 s Program je končal z neničelno kodo
Stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 >= 8
	at java.util.Vector.elementAt(Vector.java:474)
	at jungle_speed.main(jungle_speed.java:70)
#8 0/9 35,152 MiB 0,000 s Program je končal z neničelno kodo
Stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 >= 8
	at java.util.Vector.elementAt(Vector.java:474)
	at jungle_speed.main(jungle_speed.java:70)
#9 0/9 33,477 MiB 0,000 s Program je končal z neničelno kodo
Stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 >= 8
	at java.util.Vector.elementAt(Vector.java:474)
	at jungle_speed.main(jungle_speed.java:70)
#10 0/9 26,750 MiB 0,000 s Program je končal z neničelno kodo
Stderr:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 >= 8
	at java.util.Vector.elementAt(Vector.java:474)
	at jungle_speed.main(jungle_speed.java:70)
#11 10/10 36,656 MiB 0,000 s OK

Ocenjevani program (jungle_speed.java):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

public class jungle_speed {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static Vector<Vector<Integer>> stanje;
	public static int[][] matrika = new int[16][72]; // v vrstici N (1-8) je
														// player hand, v
														// vrstici 7+N je deck
														// od igralca N
	public static int activePlayer = 0;
	public static int[] active;
	public static int[] atCard;

	public static void main(String[] args) throws NumberFormatException, IOException {
		int st_igralcev = Integer.parseInt(br.readLine());
		stanje = new Vector<Vector<Integer>>(st_igralcev);
		active = new int[st_igralcev];
		atCard = new int[st_igralcev];
		String karte = br.readLine();
		String[] arrayKart = karte.split(" ");
		int currPlayer = 0;

		for (int i = 0; i < st_igralcev; i++) {
			stanje.add(new Vector<Integer>());
		}
		for (int i = 0; i < arrayKart.length; i++) {
			if (currPlayer == st_igralcev) {
				currPlayer = 0;
			}
			stanje.elementAt(currPlayer).add(Integer.parseInt(arrayKart[i])); // polnjemo
																				// deck
																				// playerjev
																				// xD
			currPlayer++;
		}
//		for (int i = 0; i < stanje.size(); i++) {
//			for (int j = 0; j < stanje.elementAt(i).size(); j++) {
//				System.out.print(stanje.elementAt(i).elementAt(j));
//			}
//			System.out.println();
//		}
//		System.exit(0);
		// System.out.println(stanje.elementAt(0).size());
		for (int i = 0; i < atCard.length; i++) {
			atCard[i] = stanje.elementAt(0).size();
		}
		int card;
		boolean found = false;
		int potentialWinner = 0;
		while (true) {
//			for (int i = 0; i < active.length; i++){
//				System.out.print(active[i] + " ");
//			}
//			System.out.println();
			
			if (activePlayer == st_igralcev) {
				activePlayer = 0;
			}
//			System.out.println("asctive:" + activePlayer);

			atCard[activePlayer] -= 1;
			if (atCard[activePlayer] < 0) {
				atCard[activePlayer] = stanje.elementAt(activePlayer).size() - 1;
			}
//			System.out.println("size: " + stanje.elementAt(activePlayer).size());
//			System.out.println("aat card za " + activePlayer + " " + atCard[activePlayer]);
			int currCard = stanje.elementAt(activePlayer).elementAt(atCard[activePlayer]);
			for (int i = 0; i < active.length; i++) {
				if (active[i] == currCard && i != activePlayer) {
					//i-ti player
					for (int j = stanje.elementAt(i).size() - 1; j >= atCard[i]; j--) {
						card = stanje.elementAt(i).elementAt(j);
//						System.out.println("cardd: " +card);
						stanje.elementAt(i).remove(j);
						stanje.elementAt(activePlayer).add(0, card);
					}
					
					//active player
					//if (atCard[activePlayer] - stanje.elementAt(activePlayer).size() == -1){
					int loop = stanje.elementAt(activePlayer).size() - atCard[activePlayer] - 1;
					int elem =  stanje.elementAt(activePlayer).size() - 1;
						for (int j = 0; j < loop; j++) {
							card = stanje.elementAt(activePlayer).elementAt(elem);
//							System.out.println("card: " +card);
							stanje.elementAt(activePlayer).remove(elem);
							stanje.elementAt(activePlayer).add(0, card);
							
						}
/*
					} else {
						for (int j = stanje.elementAt(activePlayer).size() - 1; j >= atCard[activePlayer]; j--) {
							card = stanje.elementAt(activePlayer).elementAt(j);
							System.out.println("card: " +card);
							stanje.elementAt(activePlayer).remove(j);
							stanje.elementAt(activePlayer).add(0, card);						
						}
					}
					
					*/
					atCard[i] = stanje.elementAt(i).size();
					atCard[activePlayer] = stanje.elementAt(activePlayer).size();
					active[activePlayer] = 0;
					active[i] = 0;
					found = true;
					potentialWinner = i;
					break;
				}
			}
			if (!found) {
				active[activePlayer] = stanje.elementAt(activePlayer).elementAt(atCard[activePlayer]);

			} else {
				if (stanje.elementAt(potentialWinner).size() == 0) {
					break;
				}
			}

			if (!found){
				activePlayer++;				
			}
//			for (int i = 0; i < stanje.size(); i++) {
//				for (int j = 0; j < stanje.elementAt(i).size(); j++) {
//					System.out.print(stanje.elementAt(i).elementAt(j));
//				}
//				System.out.println();
//			}
			found = false;
			potentialWinner = 0;
		}
		System.out.println(potentialWinner+1);
	}
}