Submission #238340

# Submission time Handle Problem Language Result Execution time Memory
238340 2020-06-10T20:15:18 Z danikoynov Datum (COCI20_datum) C++14
40 / 50
47 ms 632 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int days(int month, int year)
{
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        return 31;
    if (month == 4 || month == 6 || month == 9 || month == 11)
        return 30;
    if (year % 4 == 0)
        return 29;
    return 28;
}

bool is_val(int year)
{
    int day = year % 10 * 10 + year / 10 % 10;
    int month = year / 100 % 10 * 10 + year / 1000 % 10;

    if (month > 12 || month < 1)
        return false;
    if (day < 1 || day > days(month, year))
        return false;

    if (day < 10)
        cout << "0";
    cout << day << ".";
    if (month < 10)
        cout << "0";
    cout << month << ".";
    if (year < 10)
        cout << "0";
    if (year < 100)
        cout << "0";
    if (year < 1000)
        cout << "0";
    cout << year << "." << endl;
    return true;
}
void solve(string s)
{
    int sz = s.size();
    sz --;
    int year = (s[sz - 4] - '0') * 1000 +
               (s[sz - 3] - '0') * 100 +
               (s[sz - 2] - '0') * 10 +
               (s[sz - 1] - '0');

    int inday = (s[0] - '0') * 10 + (s[1] - '0');
    int inmonth = (s[3] - '0') * 10 + (s[4] - '0');
    bool tf = true;

    int day = year % 10 * 10 + year / 10 % 10;
    int month = year / 100 % 10 * 10 + year / 1000 % 10;

    if (month > 12 || month < 1)
        tf = false;
    if (day < 1 || day > days(month, year))
        tf = false;
    if (inmonth > month)
        tf = false;
    if (inmonth == month && inday > day)
        tf = false;

    if (tf)
    {
        if (day < 10)
            cout << "0";
        cout << day << ".";
        if (month < 10)
            cout << "0";
        cout << month << ".";
        if (year < 10)
            cout << "0";
        if (year < 100)
            cout << "0";
        if (year < 1000)
            cout << "0";
        cout << year << "." << endl;
    }
    else
    {
        year ++;
        while(!is_val(year))
            year ++;
    }
}
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    string s;
    while(n --)
    {
        cin >> s;
        solve(s);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Incorrect 46 ms 632 KB Output isn't correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 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 4 ms 384 KB Output is correct
10 Incorrect 47 ms 632 KB Output isn't correct