백준 1476

hong030·2023년 3월 3일
0
  • 실버 5단계 문제

풀이)
우리가 사는 곳의 연도를 N이라 할 때,
N을 1씩 증가시키며 입력받은 E S M과 비교하여 맞는 게 나올 때까지 하면 된다.

내 코드)

import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int e = Integer.parseInt(st.nextToken());
        int s = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int E = 0;
        int S = 0;
        int M = 0;
        int year = 0;
        while (true) {
            year++;
            E++;
            S++;
            M++;
            if (E == 16) E=1;
            if (S==29) S=1;
            if (M==20) M=1;
            if (e == E && m == M && S == s) break;
        }
        System.out.print(year);
    }
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글