Submission #238447

# Submission time Handle Problem Language Result Execution time Memory
238447 2020-06-11T11:07:51 Z dimitar_ne Datum (COCI20_datum) C++14
50 / 50
50 ms 504 KB
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;


struct date
{
    int day, month, year;
    int idx;
    date () {}
    date (int _day, int _month, int _year)
    {
        day = _day;
        month = _month;
        year = _year;
    }
};

int get_idx(date d)
{
    int res = d.year * 365 + d.year / 4;
    for (int i = 0; i < d.month; ++i)
        res += days[i];
    res += d.day;

    return res;
}

bool check(date d)
{
    int day = d.day;
    int month = d.month;
    int year = d.year;

    if (day / 10 != year % 10)
        return 0;
    if (day % 10 != (year / 10) % 10)
        return 0;
    if (month / 10 != (year / 100) % 10)
        return 0;
    if (month % 10 != year / 1000)
        return 0;
    return 1;
}

bool is_valid(int day, int month, int year)
{
    if (month > 12 || day > 31 || month < 1 || day < 1)
        return 0;
    if (year % 4 == 0)
        days[2] = 29;
    if (day <= days[month])
        return 1;
    return 0;
}

date check_year(int year)
{
    int month = ((year / 100) % 10) * 10 + year / 1000;
    int day = (year % 10) * 10 + ((year / 10) % 10);
    if (is_valid(day, month, year))
        return date(day, month, year);
    return date(-1, -1, -1);
}

date get_ans(date d)
{
    date ans = check_year(d.year);
    if (ans.day != -1)
    {
        if (get_idx(ans) > get_idx(d))
            return ans;
    }

    for (int tmp = d.year + 1; ; ++tmp)
    {
        ans = check_year(tmp);
        if (get_idx(ans) >= get_idx(d))
            return ans;
    }

    return date (-1, -1, -1);
}

date convert(string s)
{
    int day = (s[0] - '0') * 10 + (s[1] - '0');
    int month = (s[3] - '0') * 10 + (s[4] - '0');
    int year = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');

    return date(day, month, year);
}

string reconvert(date d)
{
    string s_day = "", s_month = "", s_year = "";

    //cout << d.day << " " << d.month << " " << d.year << endl;

    if (d.day < 10)
    {
        s_day = "0";
        s_day += char(d.day + '0');
    }
    else
    {
        s_day = char(d.day / 10 + '0');
        s_day += char(d.day % 10 + '0');
    }

    if (d.month < 10)
    {
        s_month = "0";
        s_month += char(d.month + '0');
    }
    else
    {
        s_month = char(d.month / 10 + '0');
        s_month += char(d.month % 10 + '0');
    }

    s_year = char(d.year % 10 + '0');
    s_year = char((d.year / 10) % 10 + '0') + s_year;
    s_year = char((d.year / 100) % 10 + '0') + s_year;
    s_year = char(d.year / 1000 + '0') + s_year;

    string ans = s_day + "." + s_month + "." + s_year + ".";
    return ans;
}

void solve()
{
    cin >> n;

    for (int test = 0; test < n; ++test)
    {
        string s;
        cin >> s;
        date curr_date = convert(s);
        date ans = get_ans(curr_date);
        //cout << ans.day << "." << ans.month << "." << ans.year << "." << endl;
        cout << reconvert(ans) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 50 ms 504 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 50 ms 504 KB Output is correct