기록하는 개발자

[백준][JAVA] 1100 : 하얀칸 본문

Algorithm

[백준][JAVA] 1100 : 하얀칸

밍맹030 2020. 1. 6. 15:33
728x90

 

문제

체스판은 8*8크기이고, 검정 칸과 하얀 칸이 번갈아가면서 색칠되어 있다. 가장 왼쪽 위칸 (0,0)은 하얀색이다. 체스판의 상태가 주어졌을 때, 하얀 칸 위에 말이 몇 개 있는지 출력하는 프로그램을 작성하시오.

 

입력

첫째 줄부터 8개의 줄에 체스판의 상태가 주어진다. ‘.’은 빈 칸이고, ‘F’는 위에 말이 있는 칸이다.

 

출력

첫째 줄에 문제의 정답을 출력한다

728x90
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan= new Scanner(System.in);
        int horse=0;
        String[] chess=new String[8];
        for(int i=0; i<8; i++) chess[i]=scan.nextLine();
        for(int i=0; i<8; i++) {
            for(int j=0; j<8; j++) {
                if(i%2==0&&j%2==0&&chess[i].charAt(j)=='F') horse++;
                else if(i%2==1&&j%2==1&&chess[i].charAt(j)=='F') horse++;
                else continue;
            }
        }
        System.out.println(horse);
    }
}http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

 

728x90