CF 445A DZY Loves Chessboard

来源:互联网 发布:js与jquery的区别 编辑:程序博客网 时间:2024/05/04 15:36
A. DZY Loves Chessboard
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

DZY loves chessboard, and he enjoys playing with it.

He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.

You task is to find any suitable placement of chessmen on the given chessboard.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).

Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.

Output

Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.

If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.

Sample test(s)
input
1 1.
output
B
input
2 2....
output
BWWB
input
3 3.-.-----.
output
B-B-----B

分析:
1.  若是遇到字符 ' . ',则进行处理。
 1)处理规则: 将' . '换成 ' W '或' B ',但是它们不能相邻。 
2.  若是遇到字符 ' - ',则不进行处理。

 
#include<stdio.h>int main (){int n,m;int i,j;char c[200][200];scanf("%d%d",&n,&m);getchar();     //一定要注意这个for(i=1;i<=n;i++){for(j=1;j<=m;j++)  scanf("%c",&c[i][j]);getchar();             //一定要注意这个}for(i=1;i<=n;i++){for(j=1;j<=m;j++){if(c[i][j]=='-'){c[i][j]='-';}else {if(i%2!=0){if(j%2!=0) c[i][j]='W';else  c[i][j]='B';}else {if(j%2!=0) c[i][j]='B';else   c[i][j]='W';  }}}}for(i=1;i<=n;i++){for(j=1;j<=m;j++){if(j!=m) printf("%c",c[i][j]);else  printf("%c\n",c[i][j]);}}return 0;}




0 0
原创粉丝点击