Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 1100번 하얀 칸 본문

YJ/C++

[백준/BOJ/C++] 1100번 하얀 칸

Team DAON 2021. 10. 27. 15:44

[문제]

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

 

[입력]

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

 

[출력]

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

 

[Source Code]

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int count = 0;

	for(int i = 1; i <= 8; i++){
		string input;
		cin >> input;
		if(i % 2 == 1){
			if(input[0] == 'F') count++;
			if(input[2] == 'F') count++;
			if(input[4] == 'F') count++;
			if(input[6] == 'F') count++;
		}
		else{
			if(input[1] == 'F') count++;
			if(input[3] == 'F') count++;
			if(input[5] == 'F') count++;
			if(input[7] == 'F') count++;
		}
	}

	cout << count;
}

[결과 화면]