Cod sursa(job #1369183)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 2 martie 2015 22:26:14
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <stack>
using namespace std;
ifstream f("nivele.in");
ofstream g("nivele.out");
stack <int> S;
int N;
void Read()
{
    f>>N;
    int current=0;
    for(int i=1;i<=N;i++)
    {
        int x;
        f>>x;
        if(S.empty())
            S.push(x),current=x;
        else
        {
            if(S.top()!=x)
                S.push(x);
            else
            {
                S.pop();
                --x;
                while(!S.empty() && x==S.top())
                    S.pop(),x--;
                S.push(x);
            }
        }
    }
    if(S.size()==1 && S.top()==1)
        g<<"DA\n";
    else
        g<<"NU\n";
}
int main()
{
    int T;
    f>>T;
    while(T--)
    {
        Read();
        while(!S.empty())
            S.pop();
    }
    return 0;
}