⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2435.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 2435 on 2007-01-01 at 17:32:03 */
#include <cstdio>
#include <algorithm>
using namespace std;

enum { LOST = -1, CAUGHT = 0, SAVED = 1 };
enum { GO = 0, STAY = 1 };
const int N = 16, L = 128;
const int DIR[][2] = { { 0, 1 }, { 0, -1 }, { -1, 0 }, { 1, 0 } };

char map[N][N];
int w, h;

int go(int&, int&, int);
int act(char*);

int main()
{
	char action[L];
	while(scanf("%d %d", &h, &w) != EOF) {
		scanf("\n");
		for(int i = 0; i < h; i++) gets(map[i]);
		int r = act(gets(action));
		if(r == SAVED) printf("Fishcanfly is saved.\n");
		else if(r == CAUGHT) printf("Poor fishcanfly and wywcgs.\n");
		else printf("Lost in map.\n");
	}
	return 0;
}

int go(int& x, int& y, int d)
{
	int cx = x+DIR[d][0], cy = y+DIR[d][1];
	if(map[cx][cy] == '#') return STAY;
	x = cx; y = cy; return GO;
}
int act(char* s)
{
	int x, y;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			if(map[i][j] == 'W') { x = i; y = j; }
	for(int i = 0; s[i] != 0; i++) {
		bool meet = false;
		switch(s[i]) {
		case 'F': go(x, y, 0); break;
		case 'B': go(x, y, 1); break;
		case 'J':
			if(go(x, y, 2) == STAY) break;
			if(map[x][y] == 'A') return CAUGHT;
			else if(map[x][y] == 'F') meet = true;
			if(go(x, y, 2) == STAY) break;
			if(map[x][y] == 'A') return CAUGHT;
			else if(map[x][y] == 'F') meet = true;
			go(x, y, 0);
		break;
		}
		while(true) {
			if(map[x][y] == 'F') meet = true;
			else if(map[x][y] == 'A') return CAUGHT;
			if(go(x, y, 3) == STAY) break;
		}
		if(meet) return SAVED;
	}
	return LOST;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -