๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/BOJ

[C++/๋ฐฑ์ค€] 1924 : 2007๋…„

728x90

๋ฌธ์ œ

์˜ค๋Š˜์€ 2007๋…„ 1์›” 1์ผ ์›”์š”์ผ์ด๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด 2007๋…„ x์›” y์ผ์€ ๋ฌด์Šจ ์š”์ผ์ผ๊นŒ? ์ด๋ฅผ ์•Œ์•„๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  x(1 ≤ x ≤ 12)์™€ y(1 ≤ y ≤ 31)์ด ์ฃผ์–ด์ง„๋‹ค. ์ฐธ๊ณ ๋กœ 2007๋…„์—๋Š” 1, 3, 5, 7, 8, 10, 12์›”์€ 31์ผ๊นŒ์ง€, 4, 6, 9, 11์›”์€ 30์ผ๊นŒ์ง€, 2์›”์€ 28์ผ๊นŒ์ง€ ์žˆ๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— x์›” y์ผ์ด ๋ฌด์Šจ ์š”์ผ์ธ์ง€์— ๋”ฐ๋ผ SUN, MON, TUE, WED, THU, FRI, SAT์ค‘ ํ•˜๋‚˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 


 

๋ฐฑ์ค€ ์—ด์‹ฌํžˆ ํ•ด์•ผ์ง€.....

์ด ๋ฌธ์ œ๋Š” ๋‚ ์งœ ์š”์ผ ๋งž์ถ”๋Š” ๊ตฌํ˜„? DP? ๋ฌธ์ œ์ด๋‹ค

์‚ฌ์‹ค ๋‚œ์ด๋„๋„ ์‰ฌ์›Œ์„œ ๋”ฑํžˆ ๋ถ„๋ฅ˜์˜ ์˜๋ฏธ๋„ ์—†๊ธดํ•จ

๋ธŒ๋ก ์ฆˆ 1ํ‹ฐ์–ด ๋ฌธ์ œ์ด๋‹ค

1์›” ์ž…๋ ฅ์€ ๋”ฐ๋กœ ๋นผ๋†จ๋‹ค๊ฐ€ ๋‚˜์ค‘์— ์™œ ์ด๋ ‡๊ฒŒ ํ–ˆ์ง€...? ์‹ถ์–ด์„œ ์ง€์›€ใ…Žใ…Ž ๋ฐ˜๋ณต๋ฌธ ํ•˜๋‚˜๋กœ ์ถฉ๋ถ„ํ•˜๋‹ค

 

#include <iostream>
#include <vector>
using namespace std;

int main(){
    vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    vector<int> month_date = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int month;
    int day;
    int answer = 0;
    cin >> month >> day;
    for (int i = 0; i < month-1; ++i){
        day += month_date[i];
    }
    answer = day % 7;
    cout << days[answer];

    return 0;
}
728x90