Cod sursa(job #1020709)

Utilizator Impaler_009Mihai Nitu Impaler_009 Data 2 noiembrie 2013 15:22:38
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <stack>

using namespace std;

ifstream fin("nivele.in");
ofstream fout("nivele.out");

int x,n,t;
stack <int> st;

void add (int x)
{
    if (st.empty())
    {
        st.push (x);
    }
    else
    {
        if (st.top() == x)
        {
            st.pop ();
            add (x-1);
        }
        else st.push (x);
    }
}

int main()
{
    fin>>t;

    for (;t;--t)
    {
        fin>>n;
        while (!st.empty()) st.pop();

        for (int i=1; i<=n; ++i)
        {
            fin>>x;
            add (x);
        }

        if (st.size()==1 && st.top()==1)
        {
            fout<<"DA";
        }
        else fout<<"NU";
        fout<<"\n";
    }
}