Pagini recente » Cod sursa (job #3030840) | Cod sursa (job #841792) | Cod sursa (job #1675879) | Cod sursa (job #643708) | Cod sursa (job #1369183)
#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;
}