# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345629 | limabeans | Datum (COCI20_datum) | C++17 | 1089 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
vector<int> M = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct date {
int month, day, year;
date(string s) {
int n = s.length();
vector<int> tmp(3);
int ptr = 0;
for (int i=0; i<n; ) {
int j=i;
while (j<n && s[j]!='.') j++;
int cur = 0;
while (i<j) {
cur *= 10;
cur += int(s[i]-'0');
i++;
}
i++;
tmp[ptr++] = cur;
}
month = tmp[0];
day = tmp[1];
year = tmp[2];
//cout<<month<<" "<<day<<" "<<year<<endl;
}
void inc() {
day++;
if ((year%4==0 && month==2 && day>29) || day > M[month]) {
day = 1;
month++;
if (month > 12) {
month = 1;
year++;
}
}
}
bool ispal() {
string m = to_string(month);
string d = to_string(day);
string y = to_string(year);
while ((int)m.length() < 2) m = "0"+m;
while ((int)d.length() < 2) d = "0"+d;
while ((int)y.length() < 4) y = "0"+y;
string cur = m+d+y;
int len = cur.length();
for (int i=0; i<len/2; i++) {
if (cur[i]!=cur[len-i-1]) return false;
}
return true;
}
string tostr() {
string m = to_string(month);
string d = to_string(day);
string y = to_string(year);
while ((int)m.length() < 2) m = "0"+m;
while ((int)d.length() < 2) d = "0"+d;
while ((int)y.length() < 4) y = "0"+y;
string cur = m+"."+d+"."+y+".";
return cur;
}
};
string solve() {
string s;
cin>>s;
date cur(s);
cur.inc();
while (!cur.ispal()) {
cur.inc();
}
return cur.tostr();
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
while (n--) {
cout<<solve()<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |