From c809347694338b74cca19947d966d88a086022aa Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Thu, 24 Jul 2025 22:43:03 +0900 Subject: [PATCH] =?UTF-8?q?[20250724]=20BOJ=20/=20G5=20/=20=ED=95=98?= =?UTF-8?q?=EB=85=B8=EC=9D=B4=20=ED=83=91=20=EC=9D=B4=EB=8F=99=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\217\231 \354\210\234\354\204\234.md" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "lkhyun/202507/24 BOJ G5 \355\225\230\353\205\270\354\235\264 \355\203\221 \354\235\264\353\217\231 \354\210\234\354\204\234.md" diff --git "a/lkhyun/202507/24 BOJ G5 \355\225\230\353\205\270\354\235\264 \355\203\221 \354\235\264\353\217\231 \354\210\234\354\204\234.md" "b/lkhyun/202507/24 BOJ G5 \355\225\230\353\205\270\354\235\264 \355\203\221 \354\235\264\353\217\231 \354\210\234\354\204\234.md" new file mode 100644 index 00000000..848c513a --- /dev/null +++ "b/lkhyun/202507/24 BOJ G5 \355\225\230\353\205\270\354\235\264 \355\203\221 \354\235\264\353\217\231 \354\210\234\354\204\234.md" @@ -0,0 +1,26 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static int cnt = 0; + static StringBuilder sb = new StringBuilder(); + public static void main(String[] args) throws Exception { + int N = Integer.parseInt(br.readLine()); + hanoi(N, 1, 2, 3); + bw.write(cnt+"\n"); + bw.write(sb.toString()); + bw.close(); + } + static void hanoi(int n, int from, int temp, int to) throws Exception{ + if(n == 0) return; + + hanoi(n-1,from, to, temp); //from에서 to로 잠깐 옮겨놓음 맨 아래 빼고 + sb.append(from).append(" ").append(to).append("\n"); //그럼 이제 from에서 원래 가고 싶은 to로 보낼 수 있으니 출력 + cnt++; + hanoi(n-1,temp,from, to); //그 담에 잠깐 올려뒀던 위에 있는거 다시 to로 올려놔야하니까 + } +} +```