Rezultati

Up. imeNalogaJezikRezultatČas oddaje
mmj-2017 Jungle Speed C++ 100/100OK 11. maj '17 @ 19:25

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 3,074 MiB 0,004 s OK
#2 9/9 3,098 MiB 0,004 s OK
#3 9/9 3,098 MiB 0,004 s OK
#4 9/9 3,094 MiB 0,004 s OK
#5 9/9 3,102 MiB 0,004 s OK
#6 9/9 3,098 MiB 0,004 s OK
#7 9/9 3,102 MiB 0,004 s OK
#8 9/9 3,078 MiB 0,004 s OK
#9 9/9 3,105 MiB 0,004 s OK
#10 9/9 3,078 MiB 0,004 s OK
#11 10/10 3,082 MiB 0,004 s OK

Ocenjevani program (main.cpp):
#include <iostream>
#include <stack>
using namespace std;


int main()
{
   /* stack<int> a;
    a.push(5);
    cout << a.top() << " ";
    a.pop();*/

    int n;
    cin >> n;
    stack<int> pl[n][2];
    stack<int> st,st2;
    int a;

    int poteza = -1;
    while(cin >> a){
        poteza++;
        pl[poteza%n][0].push(a);
    }
    poteza = 0;
    while(true){

        if (!pl[poteza][0].empty()){
            pl[poteza][1].push(pl[poteza][0].top());
            pl[poteza][0].pop();

        }
        else{
            if(pl[poteza][1].empty()){

                cout << poteza+1 << endl;
                break;
            }
            while(!pl[poteza][1].empty()){
                  pl[poteza][0].push(pl[poteza][1].top());
                  pl[poteza][1].pop();
            }
            pl[poteza][1].push(pl[poteza][0].top());
            pl[poteza][0].pop();
        }
        for(int i = 0; i < n; i++){
            if(i == poteza){
                continue;
            }
            if (pl[i][1].empty()){
                continue;
            }
            if(pl[i][1].top() == pl[poteza][1].top()){
                while(!pl[poteza][1].empty()){
                    st.push(pl[poteza][1].top());
                    pl[poteza][1].pop();
                }
                 while(!pl[i][1].empty()){
                    st.push(pl[i][1].top());
                    pl[i][1].pop();
                }
                while (!st.empty()){
                    st2.push(st.top());
                    st.pop();
                }
                while (!pl[poteza][0].empty()){
                    st.push(pl[poteza][0].top());
                    pl[poteza][0].pop();
                }
                while (!st2.empty()){
                    pl[poteza][0].push(st2.top());
                    st2.pop();
                }
                while (!st.empty()){
                    pl[poteza][0].push(st.top());
                    st.pop();
                }
                poteza--;
                break;
            }
        }
        poteza++;
        poteza %= n;
    }
    return 0;
}