Cod sursa(job #578579)

Utilizator ChallengeMurtaza Alexandru Challenge Data 11 aprilie 2011 13:23:38
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <stack>

using namespace std;

const char InFile[]="nivele.in";
const char OutFile[]="nivele.out";

ifstream fin(InFile);
ofstream fout(OutFile);

int T,N,x;
stack<int> S;

int main()
{
	fin>>T;
	for(register int t=1;t<=T;++t)
	{
		while(!S.empty())
		{
			S.pop();
		}
		fin>>N;
		for(register int i=1;i<=N;++i)
		{
			fin>>x;

			while(!S.empty())
			{
				if(S.top()!=x)
				{
					break;
				}
				S.pop();
				--x;
			}
			S.push(x);
		}
		if(S.size()==1 && S.top()==1)
		{
			fout<<"DA\n";
		}
		else
		{
			fout<<"NU\n";
		}
	}
	fin.close();
	fout.close();
	return 0;
}