File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
weekly/week10/BOJ_12919_A와B2 Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments