문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QLkdKAz4DFAUq


문제의 저작권은 SW Expert Academy에 있습니다.



#include <iostream>
 
using namespace std;
 
bool isValid(int month, int day) {
    bool valid;
 
    switch(month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            if(day <= 31)
                valid = true;
            else
                valid = false;
            break;
        case 2:
            if(day <= 28)
                valid = true;
            else
                valid = false;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            if(day <= 30)
                valid = true;
            else
                valid = false;
            break;
        default:
            valid = false;
            break;
    }
    return valid;
}
 
int main(void) {
    int T;
 
    cin >> T;
 
    for(int t_case=0; t_case<T; t_case++) {
        int year, month, day;
        string str;
        cin >> str;
 
        year = stoi(str.substr(0,4));
        month = stoi(str.substr(4,2));
        day = stoi(str.substr(6,2));
 
        cout << "#" << t_case+1 << " ";
 
        if(isValid(month, day)) {
            cout << str.substr(0,4<< "/" << str.substr(4,2<< "/" << str.substr(6,2<< "\n";
        } else {
            cout << "-1\n";
        }
    }
 
    return 0;
}
cs

'C & C++ > SW Expert Academy' 카테고리의 다른 글

SWEA 2047 - 신문 헤드라인  (0) 2018.04.27
SWEA 2050 - 알파벳을 숫자로 변환  (0) 2018.04.27
SWEA 2058 - 자릿수 더하기  (0) 2018.04.27
SWEA 2063 - 중간값 찾기  (0) 2018.04.27
SWEA 2068 - 최대수 구하기  (0) 2018.04.27

+ Recent posts