您的位置:首页 > 其它

Codeforces 445A DZY Loves Chessboard(水题)

2014-07-08 00:06 351 查看
题目连接: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: