Algorithm/[BOJ] - JAVA
[백준] 1100 : 하얀 칸 JAVA 풀이
Codew
2022. 6. 18. 18:03
8x8인 체스판에서 흰색인 칸은
(0,0) (0,2) (0,4) (0,6)
(1,1) (1,3) (1,5) (1,7) 등...
행 값을 i 열 값을 j라고 했을 때 i+j가 짝수인 경우이다.
따라서 체스판의 값을 입력받은 뒤에 i+j가 짝수이고,
그 자리에 'F'가 저장돼있다면 카운트를 증가시켜줬다.
import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = new String[8];
for(int i=0;i<8;i++){
str[i] = br.readLine();
}
int cnt = 0;
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
if((i+j)%2==0&&str[i].charAt(j)=='F')
cnt++;
}
}
System.out.println(cnt);
}
}