Cod sursa(job #2759239)
Utilizator | Ilascu Beatrice Georgiana Jeom | Data | 16 iunie 2021 12:21:28 |
---|---|---|---|
Problema | Nivele | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.77 kb |
#include <fstream>
#include <stack>
using namespace std;
ifstream fin("nivele.in");
ofstream fout("nivele.out");
int n,q;
int main()
{
int i,x,j;
fin>>q;
for(j=1;j<=q;++j)
{
fin>>n;
stack <int> S;
for(i=1;i<=n;++i)
{
fin>>x;
if(S.empty())S.push(x);
else
{
if(S.top()!=x)S.push(x);
else
{
while(!S.empty()&&S.top()==x)/// x=1
{
S.pop();
x--;
}
S.push(x);
}
}
}
if(!S.empty()&&S.top()==1)fout<<"DA\n";
else fout<<"NU\n";
}
return 0;
}