Rezultati

Up. imeNalogaJezikRezultatČas oddaje
kira Jungle Speed C# 100/100OK 11. maj '17 @ 19:24

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 21,988 MiB 0,000 s OK
#2 9/9 20,020 MiB 0,000 s OK
#3 9/9 22,027 MiB 0,000 s OK
#4 9/9 18,039 MiB 0,000 s OK
#5 9/9 19,996 MiB 0,000 s OK
#6 9/9 22,012 MiB 0,000 s OK
#7 9/9 23,977 MiB 0,000 s OK
#8 9/9 22,023 MiB 0,000 s OK
#9 9/9 21,777 MiB 0,000 s OK
#10 9/9 21,945 MiB 0,000 s OK
#11 10/10 21,965 MiB 0,000 s OK

Ocenjevani program (Program.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace jungle_speed
{
    class Igralec
    {
        public int index;
        public Queue<int> players_deck;
        public Stack<int> first_deck;
        public Stack<int> table_deck;
        public List<int> rotated_deck;

        public Igralec(int index)
        {
            this.index = index;
            players_deck = new Queue<int>();
            rotated_deck = new List<int>();
            first_deck = new Stack<int>();
            table_deck = new Stack<int>();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            List<Igralec> igralci = new List<Igralec>();
            int stevilo_igralcev = Int32.Parse(Console.ReadLine());
            for(int i=0;i<stevilo_igralcev;i++)
            {
                igralci.Add(new Igralec(i+1));
            }
            string[] karte = Console.ReadLine().Split();
            List<int> deck = new List<int>();
            foreach (string s in karte)
            {
                deck.Add(Int32.Parse(s));
            }
            int tosser = 0;
            foreach(int card in deck)
            {
                if (tosser == stevilo_igralcev)
                    tosser = 0;
                igralci[tosser].first_deck.Push(card);
                tosser++;
            } //vsem se razdeli karte

            foreach(Igralec igr in igralci)
            {
                while(igr.first_deck.Count > 0)
                {
                    igr.players_deck.Enqueue(igr.first_deck.Pop());
                } //tu je ok
            } //imajo zdaj zacetno roko

            int players_turn = 0;
            int winner = -1;
            Igralec current_player = igralci[players_turn];
            while(winner == -1)
            {
                if(current_player.players_deck.Count == 0) //ce ima prazno roko
                {
                    while(current_player.table_deck.Count > 0)
                    {
                        current_player.rotated_deck.Add(current_player.table_deck.Pop());
                    }
                    for (int i = current_player.rotated_deck.Count - 1; i >= 0; i--)
                    {
                        current_player.players_deck.Enqueue(current_player.rotated_deck[i]);
                    }
                    current_player.rotated_deck.Clear();
                    current_player.table_deck.Clear();
                }
                current_player.table_deck.Push(current_player.players_deck.Dequeue()); //na mizo damo karto
                bool switch_happened = false;
                foreach(Igralec igr in igralci)
                {
                    if(igr.index != current_player.index)
                    {
                        
                        if (igr.table_deck.Count > 0 && current_player.table_deck.Count > 0)
                        {
                            if (igr.table_deck.Peek() == current_player.table_deck.Peek()) //ce je ista karta na mizi
                            {
                                switch_happened = true;
                                foreach (int card in current_player.table_deck)
                                {
                                    current_player.rotated_deck.Add(card);
                                } //iz drugega playera stacka pusham v ta list
                                while (igr.table_deck.Count > 0)
                                {
                                    current_player.rotated_deck.Add(igr.table_deck.Pop());
                                }
                                for (int i = current_player.rotated_deck.Count - 1; i >= 0; i--)
                                {
                                    current_player.players_deck.Enqueue(current_player.rotated_deck[i]);
                                }
                                current_player.rotated_deck.Clear();
                                current_player.table_deck.Clear();
                                igr.table_deck.Clear();
                                break;
                            }
                        }
                    }
                }
                if(switch_happened == false)
                {
                    players_turn++;
                    if(players_turn == stevilo_igralcev)
                    {
                        players_turn = 0;
                    }
                    current_player = igralci[players_turn];
                }
                foreach(Igralec igr in igralci)
                {
                    if(igr.table_deck.Count == 0 && igr.players_deck.Count == 0)
                    {
                        winner = igr.index;
                        break;
                    }
                }
                switch_happened = false;
            }
            Console.WriteLine(winner);
        }
    }
}