답안 #845349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845349 2023-09-06T13:14:57 Z vjudge1 Datum (COCI20_datum) C++17
50 / 50
18 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
bool check(string _year){
	reverse(_year.begin(), _year.end());
	while (_year.length()<4) _year.push_back('0');
	reverse(_year.begin(), _year.end());
	int day = (_year[3]-'0')*10+(_year[2]-'0');
	int month = (_year[1]-'0')*10+(_year[0]-'0');
	int year = _year[0]*1000+_year[1]*100+_year[2]*10+_year[3];
	if (month<=0 || month>=13) return false;
	int ma = 31;
	if (month==4) ma = 30;
	if (month==6) ma = 30;
	if (month==9) ma = 30;
	if (month==11) ma = 30;
	if (month==2){
		ma=28;
		if (year%4==0) ma=29;
	}
	if (day<=0 || day>ma) return false;
	return true;
}
string make(int num){
	string year = to_string(num);
	reverse(year.begin(), year.end());
	while (year.length()<4) year.push_back('0');
	reverse(year.begin(), year.end());
	string ret = "";
	ret.push_back(year[3]);
	ret.push_back(year[2]);
	ret.push_back('.');
	ret.push_back(year[1]);
	ret.push_back(year[0]);
	ret.push_back('.');
	ret.push_back(year[0]);
	ret.push_back(year[1]);
	ret.push_back(year[2]);
	ret.push_back(year[3]);
	ret.push_back('.');
	return ret;
}
string getmonth(string date){
	return date.substr(3,2);
}
string getyear(string date){
	return date.substr(6,4);
}
string getday(string date){
	return date.substr(0,2);
}
int32_t main(){
	int n;cin>>n;
	vector<int> dp(10000,-1);
	auto f = [&](int year, auto f)->int{
		if (dp[year]!=-1) return dp[year];
		if (check(to_string(year))) return dp[year]=year;
		return dp[year]=f(year+1,f);
	};
	while (n--){
		string str;cin>>str;
		int cry = (str[6]-'0')*1000+(str[7]-'0')*100+(str[8]-'0')*10+(str[9]-'0');
		string hehe = make(cry);
		if (!(!check(to_string(cry)) || getyear(hehe)<getyear(str) || (getyear(hehe)==getyear(str) && getmonth(hehe)<getmonth(str)) || (getyear(hehe)==getyear(str) && getmonth(hehe)==getmonth(str) && getday(hehe)<=getday(str)))){
			cout<<hehe<<endl;
			continue;
		}
		cry++;
		cout<<make(f(cry,f))<<endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 18 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 16 ms 600 KB Output is correct