알고리즘 풀이/백준
[백준][Java] 1100번 하얀 칸
배게
2018. 4. 21. 06:01
728x90
체스판의 8X8 배열을 모두 받은 후에
짝수번줄 짝수번째에 , 홀수번줄 홀수번째에
하얀말이 올려진 경우
res값을 counting시켜줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner (System.in); String[] chess_board = new String[8]; int res=0; for(int i=0;i<8;i++) { chess_board[i] = sc.nextLine(); } for(int i=0;i<8;i++) { for(int j=0;j<8;j++) { if(i%2==0 && j%2==0 && chess_board[i].charAt(j)=='F') res++; else if (i%2==1 && j%2==1 && chess_board[i].charAt(j)=='F') res++; } } System.out.println(res); } } |