Submission #335257

# Submission time Handle Problem Language Result Execution time Memory
335257 2020-12-11T17:37:28 Z ronnith Datum (COCI20_datum) C++14
50 / 50
161 ms 624 KB
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;

bool pal(string a){
	int n = a.size();
	for(int i = 0;i < 8;i ++){
		if(a[i] != a[n - i - 1])return false;
	}
	return true;
}

bool cmp(string a, string b){
	int dd1 = (a[0] - '0') * 10 + (a[1] - '0');
	int mm1 = (a[3] - '0') * 10 + (a[4] - '0');
	int yy1 = (a[6] - '0') * 1000 + (a[7] - '0') * 100 + (a[8] - '0') * 10 + (a[9] - '0');

	int dd2 = (b[0] - '0') * 10 + (b[1] - '0');
	int mm2 = (b[3] - '0') * 10 + (b[4] - '0');
	int yy2 = (b[6] - '0') * 1000 + (b[7] - '0') * 100 + (b[8] - '0') * 10 + (b[9] - '0');

	if(yy1 == yy2){
		if(mm1 == mm2)return dd1 < dd2;
		return mm1 < mm2;
	}
	return yy1 < yy2;
}

int m1[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m2[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool valid(string a, bool leap){
	int dd = (a[0] - '0') * 10 + (a[1] - '0');
	int mm = (a[2] - '0') * 10 + (a[3] - '0');
	// cerr << "dd : " << dd << " " << "mm : " << mm << '\n';
	if(leap){
		if(mm > 0 and mm <= 12 and dd > 0 and dd <= m2[mm - 1])return true;
	} else {
		if(mm > 0 and mm <= 12 and dd > 0 and dd <= m1[mm - 1])return true;
	}
	return false;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tt;
	cin >> tt;
	while(tt --){
		string s;
		cin >> s;
		int yy = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');
		for(;yy <= 9999;yy ++){
			string S = "    ";
			S[0] = char((yy / 1000) % 10 + '0');
			S[1] = char((yy / 100) % 10 + '0');
			S[2] = char((yy / 10) % 10 + '0');
			S[3] = char(yy % 10 + '0');
			reverse(all(S));
			if(valid(S, yy % 4 == 0)){
				string ans = "           ";
				ans[0] = S[0];
				ans[1] = S[1];
				ans[2] = '.';
				ans[3] = S[2];
				ans[4] = S[3];
				ans[5] = '.';
				ans[6] = char((yy / 1000) % 10 + '0');
				ans[7] = char((yy / 100) % 10 + '0');
				ans[8] = char((yy / 10) % 10 + '0');
				ans[9] = char(yy % 10 + '0');
				ans[10] = '.';
				if(cmp(s, ans)){
					cout << ans << '\n';
					break;
				}
			}
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 161 ms 624 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 151 ms 620 KB Output is correct