Skip to content

Commit 3ad683e

Browse files
authored
[Week10] BOJ 12919: A와 B 2 (#70)
* [Week2] BOJ 1965: 상자넣기 * [Week10] BOJ 12919: A와 B 2
1 parent c739c69 commit 3ad683e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
# 1. 프로젝트 이름 설정 (원하는 이름으로 변경 가능)
4+
project(MyProject)
5+
6+
# 2. C++ 표준 설정 (C++11, 14, 17, 20 중 선택)
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
10+
# 3. 실행 파일 생성
11+
# add_executable(실행파일명 소스파일.cpp)
12+
# 예: main.cpp를 컴파일하여 my_program이라는 실행 파일을 만듦
13+
add_executable(my_program /weekly/week02/BOJ_1965_상자넣기/Hexeong.cpp)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.io.BufferedReader;
2+
import java.io.InputStreamReader;
3+
4+
public class Main {
5+
// AI의 피드백 : SB를 1개로 유지하고 process가 끝난 이후 원상태로 복구하는 방식으로 최적화하자.
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
9+
String S = br.readLine();
10+
String T = br.readLine();
11+
12+
StringBuilder sb = new StringBuilder(T);
13+
14+
System.out.println(process(sb, S) ? 1 : 0);
15+
}
16+
17+
private static boolean process(StringBuilder sb, String S) {
18+
if (sb.toString().equals(S)) {
19+
return true;
20+
}
21+
if (sb.length() <= S.length()) {
22+
return false;
23+
}
24+
25+
if (sb.charAt(sb.length() - 1) == 'A' && process(removeAtoSb(sb), S)) {
26+
return true;
27+
}
28+
return sb.charAt(0) == 'B' && process(reverseAndDeleteBtoSb(sb), S);
29+
};
30+
31+
private static StringBuilder removeAtoSb(StringBuilder sb) {
32+
return new StringBuilder(sb).deleteCharAt((sb.length() - 1));
33+
}
34+
35+
private static StringBuilder reverseAndDeleteBtoSb(StringBuilder sb) {
36+
return new StringBuilder(sb).reverse().deleteCharAt((sb.length() - 1));
37+
}
38+
}

0 commit comments

Comments
 (0)