https://programmers.co.kr/learn/courses/30/lessons/12901
์ฝ๋ฉํ ์คํธ ์ฐ์ต - 2016๋ | ํ๋ก๊ทธ๋๋จธ์ค
2016๋ 1์ 1์ผ์ ๊ธ์์ผ์ ๋๋ค. 2016๋ a์ b์ผ์ ๋ฌด์จ ์์ผ์ผ๊น์? ๋ ์ a ,b๋ฅผ ์ ๋ ฅ๋ฐ์ 2016๋ a์ b์ผ์ด ๋ฌด์จ ์์ผ์ธ์ง ๋ฆฌํดํ๋ ํจ์, solution์ ์์ฑํ์ธ์. ์์ผ์ ์ด๋ฆ์ ์ผ์์ผ๋ถํฐ ํ ์์ผ๊น์ง ๊ฐ๊ฐ SUN,MON,TUE,WED,THU,FRI,SAT ์ ๋๋ค. ์๋ฅผ ๋ค์ด a=5, b=24๋ผ๋ฉด 5์ 24์ผ์ ํ์์ผ์ด๋ฏ๋ก ๋ฌธ์์ด TUE๋ฅผ ๋ฐํํ์ธ์. ์ ํ ์กฐ๊ฑด 2016๋ ์ ์ค๋ ์ ๋๋ค. 2016๋ a์ b์ผ์ ์ค์ ๋ก ์๋ ๋ ์ ๋๋ค.
programmers.co.kr
<2016๋ >
โ ์ฒ์ ํผ ํ์ด(์์ ๋ชปํ์ด์ ์์ด๋์ด๋ณด๊ณ ๋ค์ํ)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
class Solution {
public String solution(int a, int b) {
String answer = "";
int[] month={31,29,31,30,31,30,31,31,30,31,30,31};
int totDate=0;
for(int i=0; i<a-1; i++)
totDate+=month[i];
totDate+=b;
switch(totDate%7){
case 1:answer+="FRI";break;
case 2:answer+="SAT";break;
case 3:answer+="SUN";break;
case 4:answer+="MON";break;
case 5:answer+="TUE";break;
case 6:answer+="WED";break;
case 0:answer+="THU";break;
}
return answer;
}
}
|
cs |