소감

2005/03/04 Accepted 0:00.000 64
힘들게 버그를 잡고 통과. 재귀함수 사용시 여러가지 통로(?)를 잘 관리해 줘야한다.

코드

~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;
}
Retrieved from http://wiki.zeropage.org/wiki.php/Slurpys/문보창
last modified 2021-02-07 05:28:02