大概意思是要找出输入的方阵中B的行与列的数量,使用二位数组去储存,然后遍历所有列与排。
需要注意的是这里如果全是B的话,output的是8。
java代码如下:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = new String[8];
char[][] ch = new char[8][8];
int i,j,num = 0,count1 = 0,count2 = 0;
for(i =0;i < 8;i++)
str[i] = sc.next();
for(i = 0;i <8;i++){
for(j = 0;j < 8;j++){
ch[i][j] = str[i].charAt(j);
}
}
for(i=0;i<8;i++){
num = 0;
for(j=0;j<8;j++){
if(ch[i][j] == 'B')
num++;
if(num == 8)
count1++;
}
}
for(i=0;i<8;i++){
num = 0;
for(j=0;j<8;j++){
if(ch[j][i] == 'B')
num++;
if(num == 8)
count2++;
}
}
if(count1 == 8 || count2 == 8)
System.out.println(8);
else
System.out.println(count1 + count2);
}
}