https://www.acmicpc.net/problem/2034
프루트포스 문제
A = 0부터 피아노를 표현했을 때 G = 10이다.
조건에서, 다음 n개의 줄에는 절댓값이 20을 넘지 않는 정수로 악보가 주어진다.
10 + 20 = 30이므로,
한 옥타브를 표현한 배열 piano의 크기 12를 두 번 넘을 수 있음을 신경써야 한다. (음의 방향 또한 마찬가지)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
class Main {
public static void main(String[] args) throws IOException {
// true = 흰 건반, false = 검은 건반
boolean[] piano = {true, false, true, true, false, true, false, true, true, false, true, false};
int[] alpa = {0, 2, 3, 5, 7, 8, 10};
Map<Integer, Character> dic = new HashMap<>();
dic.put(0, 'A');
dic.put(2, 'B');
dic.put(3, 'C');
dic.put(5, 'D');
dic.put(7, 'E');
dic.put(8, 'F');
dic.put(10, 'G');
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int M = Integer.parseInt(br.readLine());
int[] m = new int[M];
for (int i = 0; i < M; i++) {
m[i] = Integer.parseInt(br.readLine());
}
for (int i = 0; i < alpa.length; i++) {
int cur = alpa[i];
int st = cur;
boolean isAns = true;
for (int j = 0; j < M; j++) {
cur += m[j];
while (cur < 0) {
cur += 12;
}
if (cur > 11) {
cur %= 12;
}
if (!piano[cur]) {
isAns = false;
break;
}
}
if (isAns) {
System.out.println(dic.get(st) + " " + dic.get(cur));
}
}
}
}
'[백준] PS > Java [실랜디]' 카테고리의 다른 글
[백준 2535] 아시아 정보올림피아드 - JAVA (0) | 2025.03.10 |
---|---|
[백준 2491] 수열 - JAVA (0) | 2025.03.10 |
[백준 1992] 쿼드트리 - JAVA (0) | 2025.03.10 |
[백준 2303] 숫자 게임 - JAVA (0) | 2025.03.09 |
[백준 2238] 경매 - JAVA (0) | 2025.03.09 |