题目连接:Codeforce 445A DZY Loves Chessboard
题目大意:给出一张n*m的图,要在'.'的位置上填B或者W,给出要求B不能和B相邻,W不能和W相邻,输出方案。
解题思路:对于'.'的位置,横纵坐标和为奇数的放B,偶数的放W。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100;
int n, m;
char s[maxn+5][maxn+5];
int main () {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s", s[i]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
if (s[i][j] == '.') {
printf("%c", (i+j)%2 ? 'W' : 'B');
} else
printf("%c", s[i][j]);
printf("\n");
}
return 0;
}