Submission #845154

#TimeUsernameProblemLanguageResultExecution timeMemory
845154vjudge1Datum (COCI20_datum)C++17
50 / 50
299 ms704 KiB
#include <bits/stdc++.h> using namespace std; #define sp " " #define endl "\n"; #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define N 200005 const int modulo = 1e9 + 7; vector<int> v = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int steps = 0; array<int, 3> palindrom(int y){ vector<int> v; int tmp = y; for (int i = 0; i < 4; i++){ v.pb(tmp % 10); tmp /= 10; } array<int, 3> date; date[0] = v[0] * 10 + v[1]; date[1] = v[2] * 10 + v[3]; date[2]= y; return date; } bool comp(array<int, 3> a, array<int, 3> b){ reverse(a.begin(), a.end()), reverse(b.begin(), b.end()); return a < b; } bool check(array<int, 3> &date){ if (date[1] > 12 || date[1] == 0 || date[0] == 0) return 0; int lim = v[date[1] - 1]; if (date[1] == 2 && date[2] % 4 == 0) lim = 29; if (date[0] > lim) return 0; return 1; } void print(array<int, 3> ans){ cout<<(ans[0] < 10 ? "0" : "")<<ans[0]<<"."<<(ans[1] < 10 ? "0" : "")<<ans[1]<<"."; if (ans[2] < 1000) cout<<"0"; if (ans[2] < 100) cout<<"0"; if (ans[2] < 10) cout<<"0"; cout<<ans[2]<<"."<<endl; } int32_t main() { fastio(); int n; cin>>n; while(n--){ string s; cin>>s; array<int, 3> date = {(s[0] - '0') * 10 + s[1] - '0', (s[3] - '0') * 10 + s[4] - '0', (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + s[9] - '0'}; for (int i = date[2]; i < 10000; i++){ array<int, 3> curr = palindrom(i); if ((comp(date, curr)) && check(curr)){ print(curr); break; } } } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...