View Code of Problem 3684

#include<string>
#include<cstring>
#include<iostream>
using namespace std;
char a[1002][1002];
int walk(int i, int j, int t)
{
	t--;
	if (a[i][j] == 'F'&&t >= -1)
		return 1;
	else if (t < -1)
		return 0;
	else
	{
		if (a[i + 1][j] == '.' || a[i + 1][j] == 'F')
		{
			int q = walk(i + 1, j, t);
			if (q == 1)
				return 1;
		}
		if (a[i - 1][j] == '.' || a[i - 1][j] == 'F')
		{
			int q = walk(i - 1, j, t);
			if (q == 1)
				return 1;
		}
		if (a[i][j + 1] == '.' || a[i][j + 1] == 'F')
		{
			int q = walk(i, j + 1, t);
			if (q == 1)
				return 1;
		}
		if (a[i][j - 1] == '.' || a[i][j - 1] == 'F')
		{
			int q = walk(i, j - 1, t);
			if (q == 1)
				return 1;
		}
	}
	return 0;
}
int main()
{
	int n, m;
	long long t;
	int x, y;
	while (cin >> n >> m >> t)
	{
		memset(a, '0', sizeof(a));
		for (int i = 1;i <= n;i++)
		{
			for (int j = 1;j <= m;j++)
			{
				cin >> a[i][j];
				if (a[i][j] == 'S')
				{
					x = i;
					y = j;
				}
			}
		}
		if (walk(x, y, t) == 1)
			cout << "Happy" << endl;
		else
			cout << "Cry" << endl;
	}
}

Double click to view unformatted code.


Back to problem 3684