Pagini recente » Cod sursa (job #2465704) | Cod sursa (job #1911660) | Cod sursa (job #2983216) | Cod sursa (job #360666) | Cod sursa (job #632409)
Cod sursa(job #632409)
#include<fstream>
#include<list>
#include<iterator>
using namespace std;
ifstream fin("tm.in");
ofstream fout("tm.out");
int main()
{
int T;
fin>>T;
while(T--)
{
list<char> l;
char s[2000];
fin>>s;
for(int i=0;i<strlen(s);i++)
l.push_back(s[i]);
list<char>::iterator it;
//verificam daca apartine limbajului a*b*c*
for(it=l.begin();it!=l.end() && (char)*it=='a';it++);
for(;it!=l.end() && (char)*it=='b';it++);
for(;it!=l.end() && (char)*it=='c';it++);
//daca nu ajungem la blanc dupa ce am trecut prin starile de mai sus
//=>nu apartine limbajului
if(it!=l.end())
{
fout<<"NU\n";
return 0;
}
//verificam a cu b
it=l.begin();
int existaA=1;
int existaB=1;
while(existaA==1 && existaB==1)
{
existaA=0;
existaB=0;
//cautam a
for(it=l.begin();it!=l.end() && (char)*it!='a';it++);
if(it!=l.end())
{
existaA=1;
*it='x';
}
for(it=l.begin();it!=l.end() && (char)*it!='b';it++);
if(it!=l.end())
{
existaB=1;
*it='y';
}
}
if(existaA == existaB && existaA==0)
fout<<"DA\n";
else
{
//demarcam b-urile
for(it=l.begin();it!=l.end();it++)
if((char)*it=='y')
*it='b';
//verificam b cu c
int existaC=1;
existaB=1;
while(existaC==1 && existaB==1)
{
existaC=0;
existaB=0;
//cautam a
for(it=l.begin();it!=l.end() && (char)*it!='c';it++);
if(it!=l.end())
{
existaC=1;
*it='z';
}
for(it=l.begin();it!=l.end() && (char)*it!='b';it++);
if(it!=l.end())
{
existaB=1;
*it='y';
}
}
if(existaC == existaB && existaC==0)
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}