Cod sursa(job #632452)
Utilizator | Data | 11 noiembrie 2011 10:15:32 | |
---|---|---|---|
Problema | Tm | Scor | 0 |
Compilator | cpp | Status | done |
Runda | arhiva-teme-fmi | Marime | 3.57 kb |
#include<fstream>
#include<cstring>
#include<iostream>
using namespace std;
ifstream f("tm.in");
ofstream g("tm.out");
struct turing{
char ch;
turing *next, *pred;
};
turing *Ma,*Mb,*Mc,*capA, *capB, *capC, *temp;
char Cuv[500];
int N;
void introdInBanda(turing *M,char c)
{
turing *m=M;
while( m->ch!='B')
m=m->next;
m->ch=c;
}
void initBanda(turing *&M)
{
if( M==NULL)
{
M=new turing;
M->ch='B';
M->pred=NULL;
M->next=NULL;
turing *m=M;
for( int i=1; i<=50;i++)
{
turing *temp= new turing;
temp->ch='B';
temp->pred=m;;
temp->next=NULL;
m->next=temp;
m=temp;
}
}
else
{
turing *m=M;
for( int i=1; i<=50; i++)
{
m->ch='B';
m=m->next;
}
}
}
int cuvBun( char Cuv[])
{
for( unsigned int i=0; i<=strlen(Cuv); i++)
if((Cuv[i]=='b' && Cuv[i+1]=='a') || (Cuv[i]=='c' && (Cuv[i+1]=='a' || Cuv[i+1]=='b')))
return 0;
return 1;
}
int main()
{
Ma=NULL;
Mb=NULL;
Mc=NULL;
f>>N;
for( int i=1; i<=N; i++)
{
f>>Cuv;
initBanda(Ma);
initBanda(Mb);
initBanda(Mc);
if( cuvBun(Cuv))
{for( unsigned int j=0; j<strlen(Cuv); j++)
if( Cuv[j]=='a')
introdInBanda(Ma,'a');
else
{if(Cuv[j]=='b')
introdInBanda(Mb,'b');
else
introdInBanda(Mc,'c');
}
capA=Ma;
capB=Mb;
capC=Mc;
while( capA->ch=='a' && capB->ch=='b')
{
capA->ch='x';
capB->ch='y';
capA=capA->next;
capB=capB->next;
}
if( capA->ch == 'B' && capB->ch == 'B' )
g<<"DA\n";}
if((capA->ch != 'B' && capB->ch == 'B' ) || (capA->ch == 'B' && capB->ch != 'B'))
{
while(capB->pred!=NULL)
{capB->ch='b';
capB=capB->pred;
}
capB->ch='b';
while( capC->ch=='c' && capB->ch=='b')
{
capC->ch='x';
capB->ch='y';
}
if ( capB->ch=='B')
{if ( capC->ch=='B' )
g<<"DA\n";
else
g<<"NU\n";}
else
g<<"NU\n";
}
else
g<<"NU\n";
}
return 0;
}