先生成nXm的BW棋盘
BWBWBWBW
WBWBWBWB
BWBWBWBW
WBWBWBWB
类似上面交替变换
然后将输入为’-’的地方替换成‘-’即可
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std; int main(){
int n,m;
cin >> n >>m;
vector<string> board(n,string(m,'B'));
for(int i = ; i < n; ++ i){
for(int j = ; j < m ; ++j){
if(i%){
if(j% == ) board[i][j] = 'W';
}else{
if(j%) board[i][j] ='W';
}
}
}
for(int i = ; i < n; ++ i){
for(int j = ; j < m; ++ j){
char ch;
cin >>ch;
if(ch == '-') board[i][j] = '-';
cout<<board[i][j];
}
cout<<endl;
}
cout<<endl;
}