💡Problem Solving/BOJ
[BOJ 21771] 가희야 거기서 자는 거 아니야 (Java)
gom20
2021. 10. 29. 12:32
문제
https://www.acmicpc.net/problem/21771
21771번: 가희야 거기서 자는 거 아니야
베게 중 8칸이 가희에 의해 가려졌으므로, 가희는 베게 위에서 자고 있습니다.
www.acmicpc.net
풀이
베개의 넓이와 베개의 원소 개수를 비교해서
베개가 가려졌는지 여부를 판단한다.
소스코드
package dp;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ11057 {
public static int R, C, GR, GC, PR, PC;
public static void input() throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
GR = Integer.parseInt(st.nextToken());
GC = Integer.parseInt(st.nextToken());
PR = Integer.parseInt(st.nextToken());
PC = Integer.parseInt(st.nextToken());
int pArea = PR*PC;
int count = 0;
for(int i = 0; i < R; i++){
String s = br.readLine();
for(int j = 0; j < C; j++){
char val = s.charAt(j);
if('P' == val){
count++;
}
}
}
if(pArea == count){
// 베개가 모두 보여짐
System.out.println(0);
} else {
// 베개가 일부 가려짐
System.out.println(1);
}
}
public static void main(String[] args) throws Exception {
input();
}
}