[백준]2007년

백준 온라인 저지

2007년

링크 : 문제 바로가기

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int x=input.nextInt();
		int y=input.nextInt();
		int [] daysList= {0,31,28,31,30,31,30,31,31,30,31,30,31};
		int result=0;
		int answer=0;
		for(x-=1;x>=0;x--) {
			result+=daysList[x];
		}
		result+=y;
		String [] whatDayList= {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
		answer=result%7;
		System.out.println(whatDayList[answer]);
		
		
	}

}
  1. 간단하게 12개의 월에 대한 정보를 담은 Array(‘daysList’)와 7개의 요일에 대한 정보를 담은 Array(‘whatDayList’)를 선언 및 초기화한다.
  2. 입력으로 들어온 월보다 1개월 작은 개월까지의 일수를 ‘daysList’와 for문을 이용해 모두 더해 result변수에 대입하고 입력으로 들어온 일수를 result에 더해서 누적해준다.
  3. result를 7로 나누었을 때 나머지값과 ‘whtaDayList’를 이용해서 해당 요일을 찾아준다.

알고리즘 : 구현

results matching ""

    No results matching ""