백준 1476번 : 날짜 계산

반응형

etc-image-0
백준 1476번 : 날짜 계산

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public void solution() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int earth = Integer.parseInt(st.nextToken());
int sun = Integer.parseInt(st.nextToken());
int moon = Integer.parseInt(st.nextToken());
int year = 1;
int E = 1;
int S = 1;
int M = 1;
while(true){
if(E>15) E=1;
if(S>28) S=1;
if(M>19) M=1;
if(E==earth && S==sun && M == moon) break;
E++;
S++;
M++;
year++;
}
System.out.println(year);
}
public static void main(String args[]) throws IOException {
new Main().solution();
}
}

while문으로 loop를 돌려서 범위에 맞게 초기화를 반복 진행 후에 입력한 값이 해당 될때 break문으로 빠져 나온 다음 출력해준다.

반응형

'개발 > 알고리즘' 카테고리의 다른 글

백준 14500번 : 테트로미노  (0) 2023.01.02
백준 1748번 : 수 이어쓰기1  (0) 2023.01.01
백준 3085번 : 사탕 게임  (0) 2022.12.29
백준 2309번 : 일곱 난쟁이  (0) 2022.12.28
백준 6588번 : 골드바흐의 추측  (0) 2022.12.28