Bomb Kirby Running
Cat Life - GT-K
2056번 연월일 달력

2023. 3. 20. 17:28SWEA

Problem Solving - Level 1 - 연월일 달력

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=1&contestProbId=AV5QLkdKAz4DFAUq&categoryId=AV5QLkdKAz4DFAUq&categoryType=CODE

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int N;
    cin>>N;
    vector<int>days={31,28,31,30,31,30,31,31,30,31,30,31};
    for(int i=1;i<=N;i++)
    {
        cout<<"#"<<i<<" ";
        string str;
        cin>>str;
         
        int month=atoi(str.substr(4,2).c_str());
        int day=atoi(str.substr(6,2).c_str());
         
        if(month>=1&&month<=12&&day>=1&&day<=days[month-1])
        {
            cout<<str.substr(0,4)<<"/"<<str.substr(4,2)<<"/"<<str.substr(6,2)<<endl;
        }
         
        else
        {
            cout<<"-1"<<endl;
        }
    }
     
}

🔊substr(a,b) 함수는

a부터 b 길이 만큼의

문자열을 반환한다

'SWEA' 카테고리의 다른 글

2063번 중간값 찾기  (0) 2023.03.20
2058번 자릿수 더하기  (0) 2023.03.20
2050번 알파벳을 숫자로 변환  (0) 2023.03.20
2047번 신문 헤드라인  (0) 2023.03.20
2046번 스탬프 찍기  (0) 2023.03.17