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

📄 2502.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 2502 on 2007-06-05 at 10:13:53 */
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int DIR[][2] = { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
const char DIRC[] = "^<v>";

const int N = 8;

char map[N][N+1];

bool legal(int x, int y) { return x >= 0 && x < N && y >= 0 && y < N; }
bool go();

int main()
{
	for(int t = 0; scanf("%s", map[0]) != EOF && map[0][0] != '-'; t++) {
		for(int i = 1; i < N; i++) scanf("%s", map[i]);
		scanf("\n");
		while(go());
		for(int i = 0; i < N; i++) printf("%s\n", map[i]);
		printf("\n");
	}
	return 0;
}

bool go()
{
	char it[16]; scanf("%s", it);
	if(it[0] == '#') return false;
	int x, y, d;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++)
		for(int k = 0; k < 4; k++)
			if(map[i][j] == DIRC[k]) { x = i; y = j; d = k; }
	if(it[0] == 't') {
		char dir[16]; scanf("%s", dir);
		if(!strcmp(dir, "left")) map[x][y] = DIRC[(d+1)&3];
		else if(!strcmp(dir, "right")) map[x][y] = DIRC[(d+3)&3];
		else if(!strcmp(dir, "back")) map[x][y] = DIRC[(d+2)&3];
	} else {
		int s; scanf("%d", &s);
		for(int i = 0; i < s; i++) {
			int cx = x+DIR[d][0], cy = y+DIR[d][1];
			if(!legal(cx, cy)) break;
			map[x][y] = '.';
			char prev = DIRC[d];
			for(int j = 1; true; j++) {
				if(prev == '.') break;
				int tx = x+j*DIR[d][0], ty = y+j*DIR[d][1];
				if(!legal(tx, ty)) break;
				swap(map[tx][ty], prev);
			}
			x = cx; y = cy;
		}
	}
	return true;
}

⌨️ 快捷键说明

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