20分求助
查看原帖
20分求助
906525
Skywalker2187楼主2023/10/16 22:36

20分求助

无论如何改,都是20′20' 代码如下:

/*
So, tell me how it felt when you walked on water
Did you get your wish?
*/
/*I hope yes.(rp++;)*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

const int N=100+10;

using namespace std;

// basic
int n,m;
char gravity;
bool board[N][N];

// input
char tmp;

bool electron=false;
bool drop=false;

struct point
{
	int xPos,yPos;
} p;

bool check()
{
	return p.xPos>=0&&p.xPos<n&&p.yPos>=0&&p.yPos<m&&board[p.xPos][p.yPos]==false;
}

int main()
{
	scanf("%d%d",&n,&m);
	scanf("%c",&gravity);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			scanf("%c",&tmp);
			if(tmp=='.'||tmp=='o')
			{
				if(tmp=='o')
				{
					drop=true;
					p.xPos=i;
					p.yPos=j;
				}
				board[i][j]=false;
			}
			else if(tmp=='x')
			{
				electron=true;
				board[i][j]=true;
			}
		}
	}

	if(!electron||!drop)
	{
		printf("%s\n","OK");
		return 0;
	}

	while(check())
	{
		if(gravity=='^')
		{
			p.yPos--;
		}
		else if(gravity=='v')
		{
			p.yPos++;
		}
		else if(gravity=='<')
		{
			p.xPos--;
		}
		else if(gravity=='>')
		{
			p.xPos++;
		}

		if(board[p.xPos][p.yPos]==true)
		{
			printf("%s\n","GG");
			return 0;
		}
	}

	printf("%s\n","OK");

	return 0;
}

麻烦各位大佬看一下。。。

2023/10/16 22:36
加载中...