티스토리 뷰

반응형

https://www.acmicpc.net/problem/1924

 

1924번: 2007년

첫째 줄에 빈 칸을 사이에 두고 x(1 ≤ x ≤ 12)와 y(1 ≤ y ≤ 31)이 주어진다. 참고로 2007년에는 1, 3, 5, 7, 8, 10, 12월은 31일까지, 4, 6, 9, 11월은 30일까지, 2월은 28일까지 있다.

www.acmicpc.net


⊙ 문제

⊙ 입력

⊙ 출력

⊙ 예제 입출력

⊙ 알고리즘 분류

  • 구현

 


 

⊙ 문제 접근 과정

 

배열로 고정값을 저장한 후 간단한 연산을 통해 구현했다. 풀이에 주석을 달아놨다.


 

⊙ 문제 풀이

 

#include <iostream>

using namespace std;

string day_of_week[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
int month_day[] = {31,28,31,30,31,30,31,31,30,31,30,31 };

int main() {
    int month, day;
    int total_day=0;
    cin >> month >> day;

    for(int i=1;i<month;i++) total_day+=month_day[i-1]; //2007년의 월 더하기

    total_day+=day+2; //초기 날짜 설정 (월요일)
    total_day= (5+total_day)%7; //날짜 계산

    cout << day_of_week[total_day]; //요일 출력
}

 


⊙ 결과

 


⊙ 마무리

 

 

NONE

 

좋아요는 로그인하지 않아도 누를 수 있습니다!

728x90
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함