站外题_求简化
  • 板块题目总版
  • 楼主xzz_0611
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/12/16 16:10
  • 上次更新2023/12/16 17:53:07
查看原帖
站外题_求简化
1005749
xzz_0611楼主2023/12/16 16:10

题目:

制作一个五子棋

#include<bits/stdc++.h>
using namespace std;
int x,y;
char arr[19][19];
bool judgment()
{
	for(int i=0;i<15;i++) for(int j=0;j<15;j++) if(arr[i][j]!='-'&&arr[i+1][j+1]==arr[i][j]&&arr[i][j]==arr[i+2][j+2]&&arr[i][j]==arr[i+3][j+3]&&arr[i][j]==arr[i+4][j+4]) return 1;
	for(int i=0;i<19;i++) for(int j=0;j<15;j++) if(arr[i][j]!='-'&&arr[i][j]==arr[i][j+1]&&arr[i][j]==arr[i][j+2]&&arr[i][j]==arr[i][j+3]&&arr[i][j]==arr[i][j+4]) return 1;
	for(int i=0;i<15;i++) for(int j=0;j<19;j++) if(arr[i][j]!='-'&&arr[i][j]==arr[i+1][j]&&arr[i][j]==arr[i+2][j]&&arr[i][j]==arr[i+3][j]&&arr[i][j]==arr[i+4][j]) return 1;
	return 0;
}
int main()
{
	for(int i=0;i<19;i++) for(int j=0;j<19;j++) arr[i][j]='-';
	cout<<"红方: O     蓝方: X"<<endl;
	while(true)
	{
		for(int i=0;i<19;i++)
		{
			for(int j=0;j<19;j++) cout<<arr[i][j]<<" ";
			cout<<endl;
		}
		do
		{
			cin>>x>>y;
		}while(arr[x-1][y-1]!='-');
		arr[x-1][y-1]='O';
		if(judgment())
		{
			cout<<"红方胜利!";
			return 0;
		}
		for(int i=0;i<19;i++)
		{
			for(int j=0;j<19;j++) cout<<arr[i][j]<<" ";
			cout<<endl;
		}
		do
		{
			cin>>x>>y;
		}while(arr[x-1][y-1]!='-');
		arr[x-1][y-1]='X';
		if(judgment())
		{
			cout<<"蓝方胜利!";
			return 0;
		}
	}
    return 0;
}
2023/12/16 16:10
加载中...