Cod sursa(job #1067652)

Utilizator andreiiiiPopa Andrei andreiiii Data 27 decembrie 2013 11:12:07
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
#include <stack>

using namespace std;

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

int main()
{
    int t, n, a;
    fin>>t;
    while(t--)
    {
        fin>>n;
        stack <int> s;
        while(n--)
        {
            fin>>a;
            while(!s.empty()&&a==s.top())
            {
                a--;
                s.pop();
            }
            s.push(a);
        }
        if(s.size()==1&&s.top()==1) fout<<"DA\n";
        else fout<<"NU\n";
    }
    fin.close();
    fout.close();
}