https://www.acmicpc.net/problem/2527
1. 아이디어
조건 분기로 해결할 수 있는 문제로 d -> c -> b -> a 순으로 찾아나갔다.
2. 문제풀이
d는 각 변의 위치 관계, c는 각 꼭짓점의 위치 관계, b도 각 변의 위치 관계로 간단히 찾을 수 있어서 해당 방식으로 if else if else 조건 분기로 구현했다.
3. 코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
for (int tc = 1; tc <= 4; tc++) {
st = new StringTokenizer(br.readLine());
int x1 = Integer.parseInt(st.nextToken());
int y1 = Integer.parseInt(st.nextToken());
int x2 = Integer.parseInt(st.nextToken());
int y2 = Integer.parseInt(st.nextToken());
int x3 = Integer.parseInt(st.nextToken());
int y3 = Integer.parseInt(st.nextToken());
int x4 = Integer.parseInt(st.nextToken());
int y4 = Integer.parseInt(st.nextToken());
if (x2 < x3 || x1 > x4 || y2 < y3 || y1 > y4) {
sb.append("d\n");
} else if ((x1 == x4 && y1 == y4) || (x1 == x4 && y2 == y3) || (x2 == x3 && y2 == y3) || (x2 == x3 && y1 == y4)) {
sb.append("c\n");
} else if ((x1 == x4) || (x2 == x3) || (y1 == y4) || (y2 == y3)) {
sb.append("b\n");
} else {
sb.append("a\n");
}
}
bw.write(sb.toString());
bw.flush();
}
}
4. 후기
'코딩테스트 준비 > 백준' 카테고리의 다른 글
[백준] 2845번 - 파티가 끝나고 난 뒤 [Java] (0) | 2025.02.02 |
---|---|
[백준] 11441번 - 합 구하기 [Java] (0) | 2025.02.02 |
[백준] 16920번 - 확장 게임 [Java] (0) | 2025.02.02 |
[백준] 16953번 - A → B [Java] (0) | 2025.02.02 |
[백준] 15792번 - A/B - 2 [Java] (0) | 2025.02.02 |