Notice
Recent Posts
Recent Comments
Today
Total
01-11 13:35
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] 2016๋…„ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] 2016๋…„

WonderJay 2022. 7. 4. 19:24
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://programmers.co.kr/learn/courses/30/lessons/12901

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - 2016๋…„

2016๋…„ 1์›” 1์ผ์€ ๊ธˆ์š”์ผ์ž…๋‹ˆ๋‹ค. 2016๋…„ a์›” b์ผ์€ ๋ฌด์Šจ ์š”์ผ์ผ๊นŒ์š”? ๋‘ ์ˆ˜ a ,b๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ 2016๋…„ a์›” b์ผ์ด ๋ฌด์Šจ ์š”์ผ์ธ์ง€ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์š”์ผ์˜ ์ด๋ฆ„์€ ์ผ์š”์ผ๋ถ€ํ„ฐ ํ† ์š”์ผ๊นŒ

programmers.co.kr

2016๋…„ 1์›” 1์ผ์€ ๊ธˆ์š”์ผ์ด๋ฏ€๋กœ,

2016 ๋…„ A์›” B์ผ ์€ A - 1 ์›”๊นŒ์ง€์˜ ์ผ ์ˆ˜ + B ๋ฅผ ๋”ํ•œ ๊ฐ’ data ๋ฅผ 7๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€์— ๋”ฐ๋ผ์„œ ์š”์ผ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

[C++]

#include <string>
#include <vector>

using namespace std;

/*
(1, 31) (2,29) (3, 31) (4, 30) (5, 31)
(6, 30) (7, 31) (8, 31) (9, 30) (10, 31)
(11, 30) (12,31)
*/

//2016. 01. 01 : FRI

string solution(int a, int b) {
    string answer = "";
    int date = 0;

    int day_arr[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    string arr[] = { "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU" };

    for (int i = 0; i < a-1; i++)
    {
        date += day_arr[i];
    }
    date += b;

    if (date % 7 - 1 != -1)
        answer = arr[date % 7 - 1];
    else // date % 7 == 0 ์ด๋ฉด arr[-1] ์ด ๋˜๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
        answer = arr[6]; 

    return answer;
}

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments