Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int const N = 1e2 + 1;
int n, m;
char g[N][N];
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%s", g[i]);
bool cur = true;
for(int i = 0; i < n; ++i) {
if(m % 2 == 0)
cur = !cur;
for(int j = 0; j < m; ++j) {
if(cur && g[i][j] != '-')
g[i][j] = 'W';
else if(!cur && g[i][j] != '-')
g[i][j] = 'B';
cur = !cur;
}
}
for(int i = 0; i < n; ++i)
puts(g[i]);
return 0;
}
Copy The Code &
Try With Live Editor
Input
1 1
.
.
Output
B
Demonstration
Codeforces Solution-DZY Loves Chessboard-Solution in C, C++, Java, Python