~cpp
// no384 - Slurpy
#include <iostream>
#include <cstring>
using namespace std;
const int MAX_LEN = 61;
bool isSlurpy(const char * str, int & index);
bool isSlimp(const char * str, int & index);
bool isSlump(const char * str, int & index);
int main()
{
int nCase;
cin >> nCase;
cin.get();
char str[MAX_LEN];
int index;
int i;
cout << "SLURPYS OUTPUTn";
for (i=0; i<nCase; i++)
{
cin.getline(str, MAX_LEN, 'n');
index = 0;
if (isSlurpy(str, index))
cout << "YESn";
else
cout << "NOn";
}
cout << "END OF OUTPUTn";
return 0;
}
bool isSlurpy(const char * str, int & index)
{
if (!isSlimp(str, index))
return false;
if (!isSlump(str, index))
return false;
if (index != strlen(str))
return false;
return true;
}
bool isSlimp(const char * str, int & index)
{
if (str[index++] != 'A')
return false;
if (str[index] == 'H')
{
index++;
return true;
}
if (str[index] == 'B')
{
index++;
if (!isSlimp(str, index))
return false;
if (str[index] == 'C')
{
index++;
return true;
}
else return false;
}
if (!isSlump(str, index))
return false;
else if (str[index] == 'C')
{
index++;
return true;
}
return false;
}
bool isSlump(const char * str, int & index)
{
if (!(str[index] == 'D' || str[index] == 'E'))
return false;
index++;
if (str[index] != 'F')
return false;
while (str[index] == 'F')
index++;
if (str[index] == 'G')
{
index++;
return true;
}
if (!isSlump(str, index))
return false;
else
return true;
return false;
}