53 RE + MLE
查看原帖
53 RE + MLE
1122193
FarmerDrone楼主2024/5/11 22:37
#include <bits/stdc++.h> 
using namespace std;

int y[5] = {0, 0, 1, 0, -1};
int x[5] = {0, -1, 0, 1, 0};
int to;
int youx, youy;
char sd[5] = {'.', '^', '>', 'v', '<'};

inline bool out(int x, int y)
{
	if (x > 8 || x < 1 || y > 8 || y < 1)
		return 1;
	else
		return 0;
}

class CHESS
{
public:
	bool live;
	char name;
	int X;
	int Y;
	bool you;
	void dlt();
	void move();
} chess[12][12];

void CHESS::dlt() 
{
	you = 0;
	live = 0;
	name = '.';
}

void CHESS::move()
{
	if (chess[this->X + x[to]][this->Y + y[to]].live)
		chess[this->X + x[to]][this->Y + y[to]].move();
	if (out(this->X + x[to], this->Y + y[to]))
		if (you)	
			return;
		else
			this->dlt();
	if (you)
		youx += x[to], youy += y[to];
	chess[this->X + x[to]][this->Y + y[to]].live = 1;
	chess[this->X + x[to]][this->Y + y[to]].name = this->name;
	chess[this->X + x[to]][this->Y + y[to]].you = this->you;
	this->dlt(); 
}

int main() 
{
	map <char, int> m;
	m['^'] = 1;
	m['>'] = 2;
	m['v'] = 3;
	m['<'] = 4;
	char ch;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
		{
			chess[i][j].live = 0;
			chess[i][j].name = '.';
			chess[i][j].Y = j;
			chess[i][j].X = i;
			chess[i][j].you = 0;
		}
	for (int i = 1; i <= 8; i++)
		for (int j = 1; j <= 8; j++)
		{
			cin >> ch;
			if (ch != '.')
			{
				if (m[ch])
				{
					youx = i;
					youy = j;
					chess[i][j].you = 1;
					to = m[ch];
				}
				chess[i][j].name = ch;
				chess[i][j].live = 1;
			}
		}
	string str;
	int n;
	cin >> str;
	while (str != "#")
	{
		if (str == "move")
		{
			scanf("%d", &n);
			while (n--)
				chess[youx][youy].move();
		} 
		if (str == "turn")
		{
			cin >> str;
			if (str == "left")
			{
				to--;
				if (!to)
					to = 4;
			}
			if (str == "right")
			{
				to++;
				if (to > 4)
					to = 1;
			}
			if (str == "back")
			{
				to -= 2;
				if (to < 1)
					to += 4; 
			}
		}
		cin >> str;
	}
	for (int i = 1; i <= 8; i++)
	{
		for (int j = 1; j <= 8; j++)
			if (chess[i][j].you)
				cout << sd[to];
			else
				cout << chess[i][j].name;
		cout << "\n"; 
	}
	return 0;
}
2024/5/11 22:37
加载中...