题解 | #井字棋#

井字棋

https://www.nowcoder.com/practice/0375c1d206ef48a3894f72aa07b2fdde

#include <stdio.h>

int main()
{
	char arr[100][100] = { 'O'};
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			scanf(" %c", &arr[i][j]);
		}
	}
	for (int i = 0; i < 3; i++)
	{

		for (int j = 0; j < 3; j++)
		{
			if (arr[i][j] == 'K' && arr[i][j + 1] == 'K' && arr[i][j + 2] == 'K')
			{
				printf("KiKi wins!\n");
				return 0;
			}
			else if(arr[i][j] == 'K' && arr[i - 1][j] == 'K' && arr[i + 1][j] == 'K')
			{
				printf("KiKi wins!\n");
				return 0;
			}
			else if (arr[i][j] == 'K' && arr[i - 1][j - 1] == 'K' && arr[i + 1][j + 1] == 'K')
			{
				printf("KiKi wins!\n");
				return 0;
			}
			else if (arr[i][j] == 'K' && arr[i - 1][j + 1] == 'K' && arr[i + 1][j - 1] == 'K')
			{
				printf("KiKi wins!\n");
				return 0;
			}
			else if (arr[i][j] == 'B' && arr[i][j + 1] == 'B' && arr[i][j + 2] == 'B')
			{
				printf("BoBo wins!\n");
				return 0;
			}
			else if (arr[i][j] == 'B' && arr[i - 1][j] == 'B' && arr[i + 1][j] == 'B')
			{
				printf("BoBo wins!\n");
				return 0;
			}
			else if (arr[i][j] == 'B' && arr[i - 1][j - 1] == 'B' && arr[i + 1][j + 1] == 'B')
			{
				printf("BoBo wins!\n");
				return 0;
			}
			else if (arr[i][j] == 'B' && arr[i - 1][j + 1] == 'B' && arr[i + 1][j - 1] == 'B')
			{
				printf("BoBo wins!\n");
				return 0;
			}
		}
	}
	printf("No winner!\n");
	return 0;
}

全部评论

相关推荐

11-08 13:58
门头沟学院 Java
程序员小白条:竟然是蓝桥杯人才doge,还要花钱申领的offer,这么好的公司哪里去找
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务