백준 알고리즘 - 11729 (하노이 탑 이동 순서)

aladin·2020년 8월 24일
0

백준알고리즘

목록 보기
15/18

문제

I.O

코드 및 해석

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Boj_11729 {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		int first = 1;
		int second = 2;
		int third = 3;
		
		hanoi(N, first, second, third);
		
	}
	
	public static void hanoi(int N, int f, int m, int t) {
		if(N == 1) {
			System.out.println(f + " " + t);
			return;
		}
		
		hanoi(N-1, f, t, m);
		
		System.out.println(f + " " + t);
		
		hanoi(N-1, m, f, t);
	}

}

문제 및 사진출처

출처 - 백준 알고리즘_11729번

profile
컴공과 대학생의 개발노트

0개의 댓글