관심있는 주제/알고리즘 문제

백준 알고리즘 1924 java

Lynn123 2018. 11. 30. 00:39
반응형

문제 : 2007년 x월 y일이 무슨 요일인지 알아내보기

입력을 1 1 로 주면 MON 로 나오도록 만들어보기


사실 이렇게 길게 짜도 되는건지는 모르겠다.

어쨌든 스위치를 써서 정답이라는 결과를 받아냄!


답 : 

import java.util.Scanner;


public class Main{

    public static void main(String[] args) {

Scanner sc =new Scanner(System.in);

int mon = sc.nextInt();

int day = sc.nextInt();

switch(mon) {

case 1 : 

switch(day%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 2 :

switch((31+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 3 :

switch((31+28+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 4 :

switch((31*2+28+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 5 :

switch((31*2+28+30+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 6 :

switch((31*3+28+30+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 7 :

switch((31*3+28+30*2+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 8 :

switch((31*4+28+30*2+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 9 :

switch((31*5+28+30*2+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 10 :

switch((31*5+28+30*3+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 11 :

switch((31*6+28+30*3+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

case 12 :

switch((31*6+28+30*4+day)%7) {

case 0 : System.out.println("SUN");break;

case 1 : System.out.println("MON");break;

case 2 : System.out.println("TUE");break;

case 3 : System.out.println("WED");break;

case 4 : System.out.println("THU");break;

case 5 : System.out.println("FRI");break;

case 6 : System.out.println("SAT");break;

}break;

}

}

}

반응형

'관심있는 주제 > 알고리즘 문제' 카테고리의 다른 글

백준 알고리즘 11720 java  (0) 2018.11.30
백준 알고리즘 8393 java  (0) 2018.11.30
백준 알고리즘 2441 java  (0) 2018.11.21
백준 알고리즘 2439 java  (0) 2018.11.21
백준 알고리즘 2440 java  (0) 2018.11.16