코딩테스트/프로그래머스

[Level 1][C++] 2016년

MJ.Lee 2024. 10. 1. 12:40
#include <string>
#include <vector>
#include <iostream>

using namespace std;

void inputDate(int& a, int& b)
{
     while (1)
     {
          try {
               cout << "무슨 달인지 입력하십시오 : ";
               cin >> a;
               if (a <= 0 || a > 12)
                    throw 0;
              cout << "몇 일인지 입력하십시오 : ";
              cin >> b;
              if (b <= 0 || b > 31)
                    throw 0;
              break;
               }
          catch (int expn) {
               cout << "잘못 입력하셨습니다. 다시 입력해주십시오. \n";
               }
     }

}

string solution(int a, int b) {
     inputDate(a, b);

     vector<int>month = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
     vector<string>days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

     int day = b;
     for (int i = 0; i < a - 1; i++)
          day += month[i];
    
     string answer = days[(4 + day) % 7];
     
     return answer;
}