Codeforces Round #157 (Div. 2)

A. Little Elephant and Chess

题意是说能否将给定的棋盘转换成相邻颜色不同的棋盘,不能想复杂了,想明白了就很简单,格局就两种情况,WBWBWBWB和BWBWBWBW,只要能转换成这两种任一种就能做调整使得满足要求。回顾 用字符数组存储字符串,用cstring中的字符串处理函数,同时别忘了,假如定义了一个字符数组c[9],若有操作cin>>c,其实就能实现输入字符串的效果。代码如下:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char a[9], b[9], c[9];
	strcpy(a, "WBWBWBWB");
	strcpy(b, "BWBWBWBW");
	int flag = 1;
	for (int i = 1; i <= 8; i++)
	{
		cin >> c;
		if (strcmp(a, c) != 0 && strcmp(b, c) != 0)
			flag = 0;
	}
	if (flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


你可能感兴趣的:(Codeforces Round #157 (Div. 2))