통나무 자르기

최민수·2023년 7월 24일
0

알고리즘

목록 보기
74/94

Python code

T = int(input())
for test_case in range(1, T + 1):
    num = int(input())
    winner = ""
    if num % 2 == 0:
        winner = "Alice"
    else:
        winner = "Bob"
    print("#" + str(test_case) + " " + winner)


Java code

import java.util.Scanner;
// import java.io.FileInputStream;

class Main
{
    public static void main(String args[]) throws Exception
    {
        // System.setIn(new FileInputStream("C:\\SSAFY\\intellij\\algorithm\\src\\input.txt"));

        Scanner sc = new Scanner(System.in);
        int T;
        T = sc.nextInt();

        for (int test_case = 1; test_case <= T; test_case++) {
            String winner = "";
            int num = sc.nextInt();
            if (num % 2 == 0) {
                winner = "Alice";
            } else {
                winner = "Bob";
            }
            System.out.println("#" + test_case + " " + winner);
        }
    }
}

D3

난이도 측정이 잘못됐나 싶을 정도로 간단한 문제였다.

결국 조건대로라면 가장 작은 자연수(1) 로 잘라야 하기 때문에, 자르는 방법에 관계없이 자르는 횟수는 정해져있다

따라서 홀수, 짝수에 따라 답이 결정된다.


출처: https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AYJW0g-qlO8DFASv

profile
CS, 개발 공부기록 🌱

1개의 댓글

comment-user-thumbnail
2023년 7월 24일

공감하며 읽었습니다. 좋은 글 감사드립니다.

답글 달기