백준 9655 자바

손찬호·2024년 8월 30일
0

알고리즘

목록 보기
88/91

https://www.acmicpc.net/problem/9655

풀이 아이디어

상근이가 이기는 경우 - 홀수일 때 3*x+1
창영이가 이기는 경우 - 짝수일 때 / 6=1 1 3 4

×3,×3+1,×3+2\times3, \times3+1, \times3+2 세 종류의 수가 있는데

3×13 \times 1= 상근
3×23\times2= 창영

3×0+13\times0+1 = 상근
3×1+13\times1+1 = 창영

3×0+23\times0+2 = 창영
3×1+23\times1+2 = 상근

이 케이스대로 나눠서 계산해주면된다.
사실 그냥 짝수면 창영이가 이기고, 홀수면 상근이가 이긴다.

풀이 코드

import java.io.*;

public class _9655 {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String answer = "";
        
        // n을 3으로 나눈 몫과 나머지를 구한다. 
        int quotient = n/3;
        int remainder = n%3;

        switch(remainder){
            case 0:
                if(quotient%2==0){
                    answer="CY";
                }
                else {
                    answer="SK";
                }
                break;
            case 1:
                if(quotient%2==0){
                    answer="SK";
                }
                else {
                    answer="CY";
                }
                break;
            case 2:
                if(quotient%2==0){
                    answer="CY";
                }
                else {
                    answer="SK";
                }
                break;
            default:
                break;
        }

        System.out.println(answer);
    }
}
profile
매일 1%씩 성장하려는 주니어 개발자입니다.

0개의 댓글

관련 채용 정보