2019/프로그래밍

날짜체크 알고리즘

fw93 2019. 8. 27. 13:12
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main() {
	int t;
	cin >> t;
	for (int z = 0; z < t; z++) {
		string date;
		cin >> date;
		vector<int> days = { 31,28,31,30,31,30,31,31,30,31,30,31 };

		int month = (date[4]-'0') * 10 + (date[5]-'0');
		if (month > 12 || month <= 0) { cout << "#" << (z + 1) << " " << "-1" << endl; continue; }
		int day = (date[6]-'0') * 10 + (date[7]-'0');
		if (day <= 0 || day > days[month - 1]) { cout << "#" << (z + 1) << " " << "-1" << endl; continue; }

		cout << "#" << (z + 1) << " ";
		for (int i = 0; i < 4; i++) {
			cout << date[i];
		}
		cout << "/" << date[4] << date[5] << "/" << date[6] << date[7] << endl;
	}
}

'2019 > 프로그래밍' 카테고리의 다른 글

C++ 벡터와 array 속도 차이  (0) 2019.08.27