Submission #335257

#TimeUsernameProblemLanguageResultExecution timeMemory
335257ronnithDatum (COCI20_datum)C++14
50 / 50
161 ms624 KiB
#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 timeMemoryGrader output
Fetching results...