Pagini recente » Cod sursa (job #1358443) | Cod sursa (job #476710) | Cod sursa (job #2438887) | Cod sursa (job #2524108) | Cod sursa (job #632294)
Cod sursa(job #632294)
// tm_list.cpp : Defines the entry point for the console application.
//
#include <list>
#include <iterator>
#include <iostream>
using namespace std;
int _tmain()
{
list<char> L;
list<char>::iterator it;
char s[1002];
int i,m,ok=1;
cin>>s;
m=strlen(s);
for(i=0;i<m;i++)
L.push_back(s[i]);
for(it=L.begin();it!=L.end() && ok;it++) //verific daca apartine limbajului
{
if((char)(*it)=='a')
{
if(++it!=L.end() && (char)(*it)!='a')
{
it--;
if((char)(*(++it))!='b')
ok=0;
it--;
}
else
it--;
}
else
if((char)(*it)=='b')
{
if(++it!=L.end() && (char)(*it)!='b')
{
it--;
if((char)(*(++it))!='c')
ok=0;
it--;
}
else
it--;
}
else
{
if(++it!=L.end() && (char)(*it)!='c')
{
ok=0;
it--;
}
else
it--;
}
}
if(ok) //apartine limbajului..marcarea va fi a cu d, b cu e, c cu f
{
it=L.begin();
for(;(char)(*it)=='a';it++)
{
*it='d';//marchez a
for(;it!=L.end() && (char)(*it)!='b';it++);
if(it!=L.end())
*it='e';//marchez b
else//daca nu exista b demarchez toate e-urile
{
for(it=L.begin();it!=L.end() && (char)(*it)!='e';it++);
if(it==L.end()) //nu exita b deloc -> accept -> b=c=0
{
cout<<"DA";
return 0;
}
for(;it!=L.end() && (char)(*it)=='e';it++)
*it='b';
}
it=L.begin();
}
if((char)(*it)!='a')//daca nu exista a
{
int okb=1;
for(it=L.begin();it!=L.end() && okb;it++) //daca nu exista b acceptam
if((char)(*it)=='b')
okb=0;
if(okb)
{
cout<<"DA";
return 0;
}
}
for(it=L.begin();it!=L.end() && (char)(*it)!='e';it++); //demarchez b`urile
for(;it!=L.end() && (char)(*it)=='e';it++)
*it='b';
for(it=L.begin();(char)(*it)!='b';it++);
for(;(char)(*it)=='b';it++)
{
for(;it!=L.end() && (char)(*it)=='b';it++)
if(it!=L.end())
{
*it='e';//marchez un b
for(;it!=L.end() && (char)(*it)!='c';it++);
if(it==L.end())//nu exista c resping
{
cout<<"NU";
return 0;
}
else
*it='f'; //marchez un c
it=L.begin();
}
}
int okc=0;
for(it=L.begin();it!=L.end();it++) //daca nu exista c acceptam altfel respingem
if((char)(*it)=='c')
{
cout<<"NU";
return 0;
}
cout<<"DA";
}
else
cout<<"NU!";
return 0;
}