์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[๋ฐฑ์ค€(BOJ)] 1924๋ฒˆ: 2007๋…„ (์ž…์ถœ๋ ฅ, C++)

PROGRAMMING/Algorithm

by koharin 2021. 2. 11. 13:09

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ“ ๋ฌธ์ œํ’€์ด ๊ณผ์ •


  • ๊ฐ 1์›”, 2์›”, ... , 12์›”์˜ ๋งˆ์ง€๋ง‰ ๋‚ ์„ ๋ฐฐ์—ด์— ์ €์žฅ
  • ์š”์ผ์— ๋Œ€ํ•œ ๋ฐฐ์—ด
  • 1์›” 1์ผ๋ถ€ํ„ฐ x์›” ์ „ ๋‹ฌ๊นŒ์ง€์˜ ๋ชจ๋“  ์š”์ผ ์ˆ˜๋ฅผ ๋”ํ•œ๋‹ค.
  • x์›”๋ถ€ํ„ฐ y์ผ๊นŒ์ง€๋ฅผ ์ง€๊ธˆ๊นŒ์ง€ ๋”ํ•œ ์š”์ผ ์ˆ˜์— ์ถ”๊ฐ€๋กœ ๋”ํ•œ๋‹ค.
  • ์ผ์ฃผ์ผ์€ 7์ผ ์ด๋ฏ€๋กœ, 7๋กœ ๋‚˜๋ˆ„๊ณ  ๋‚จ์€ ๋‚˜๋จธ์ง€๋กœ, ์š”์ผ ๋ฐฐ์—ด์˜ ํ•ด๋‹น ์ธ๋ฑ์Šค์˜ ์š”์ผ์„ ๊ฐ€์ ธ์™€ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ’ป C++ ์ œ์ถœ์ฝ”๋“œ


#include <stdio.h>
#include <iostream> // string

using namespace std;

int main(){
    int x,y, day=0;
    string str[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int last[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    scanf("%d %d", &x, &y);

    for(int i=0; i<x-1; i++){
        day += last[i]; // sum days from january to before x
    }
    day += y; // all days from beginning of x to y

    cout << str[day%7];
    
    
}

 

๐Ÿ‘ ๊ฒฐ๊ณผ


728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ