티스토리 뷰

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

 

1476번: 날짜 계산

준규가 사는 나라는 우리가 사용하는 연도와 다른 방식을 이용한다. 준규가 사는 나라에서는 수 3개를 이용해서 연도를 나타낸다. 각각의 수는 지구, 태양, 그리고 달을 나타낸다. 지구를 나타

www.acmicpc.net

 

브루트포스 + 단순 구현 문제.

 

import java.util.Scanner;

public class Main{
    public static Scanner sc;
    public static int E, S, M;
    
    public static void main(String[] args)
    {
        solve();
    }

    public static void solve(){
        input();
        bruteforce();
    }

    public static void input(){
        sc = new Scanner(System.in);
        E = sc.nextInt();
        S = sc.nextInt();
        M = sc.nextInt();
    }

    public static void bruteforce(){
        int year = 1;
        int e_cnt = 1;
        int s_cnt = 1;
        int m_cnt = 1;

        while(true){
            if(e_cnt == E && s_cnt == S && m_cnt == M)
                break;
            
            year++;
            e_cnt++;
            s_cnt++;
            m_cnt++;

            if(e_cnt > 15)
                e_cnt = 1;
            
            if(s_cnt > 28)
                s_cnt = 1;

            if(m_cnt > 19)
                m_cnt = 1;
        }

        System.out.println(year);
    }
}

'알고리즘' 카테고리의 다른 글

백준 실버II. 1182번 부분수열의 합  (0) 2022.05.03
실버I. 백준2293 동전1  (0) 2021.12.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함