# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237630 | akat | Datum (COCI20_datum) | C++14 | 18 ms | 512 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;
int get(string &s,int i,int n)
{
int ans = 0;
for(;i<n;i++)
ans = ans * 10 + s[i] - '0';
return ans;
}
int rev(int x)
{
return (x % 10) * 10 + x / 10;
}
const int MONTHS = 12;
int month_len[MONTHS+1] = {-1,31,29,31,30,31,30,31,31,30,31,30,31};
void print(int x,int len)
{
int y = x;
while(y)
{
y /= 10;
len--;
}
while(len--)
cout<<0;
cout<<x<<'.';
}
void solve()
{
string s;
cin>>s;
int day = get(s,0,2);
int month = get(s,3,5);
int year = get(s,6,10);
int palmonth = (year % 1000) / 100 * 10 + year / 1000;
int palday = (year % 10) * 10 + (year % 100) / 10;
if(palmonth > month || (palmonth == month && palday > day))year--;
int ansday,ansmonth,ansyear=1e4;
int cday,cmonth,cyear;
for(cmonth = 1;cmonth < 13;cmonth++)
for(cday = 1;cday <= month_len[cmonth];cday++)
{
cyear = rev(cmonth) * 100 + rev(cday);
if(cyear < ansyear && cyear > year)
{
ansyear = cyear;
ansmonth = cmonth;
ansday = cday;
}
}
print(ansday,2);
print(ansmonth,2);
print(ansyear,4);
cout<<'\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |