알고리즘/백준
백준 22935번 이진딸기 (JAVA)
왕구스
2021. 10. 2. 00:50
https://www.acmicpc.net/problem/22935
22935번: 이진 딸기
첫 줄에 테스트 케이스의 개수 T(1 ≤ T ≤ 1,000)가 주어진다. 이후 T개의 줄에 걸쳐 이진 딸기를 처음 시작한 사람으로부터 몇 차례 후에 해강이가 말해야 하는지 N (1 ≤ N ≤ 1,000,000,000) 이 정
www.acmicpc.net
친애하는 바이너리 윤 선생님의 모의 코딩테스트 대회 1번이었던 문제.
문자열 문제이며, 어렵게 접근할 필요는 없는 문제이다.
package BOJ.문자열;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public class BOJ_22935_이진딸기 {
static Function<String, Integer> stoi = Integer::parseInt;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = stoi.apply(br.readLine());
List<String> ans = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 15; i++) {
sb.setLength(0);
String binary = Integer.toBinaryString(i);
if (binary.length() < 4) {
sb.append("V".repeat(Math.max(0, 4 - binary.length())));
}
for (int j = 0; j < binary.length(); j++) {
char c = binary.charAt(j);
if (c - '0' == 0) {
sb.append("V");
} else {
sb.append("딸기");
}
}
ans.add(sb.toString());
}
for (int i = 0; i < N; i++) {
int num = stoi.apply(br.readLine());
if (num > 15) {
int num2 = num - 16;
int p = num2 / 14;
int q = num2 % 14;
if (p % 2 == 0) { //양수
System.out.println(ans.get(13 - q));
} else {
System.out.println(ans.get(q + 1));
}
} else {
System.out.println(ans.get(num - 1));
}
}
}
}