Submission #736152

# Submission time Handle Problem Language Result Execution time Memory
736152 2023-05-05T09:08:26 Z marvinthang Datum (COCI20_datum) C++17
50 / 50
11 ms 720 KB
/*******************************
*    @author : @marvinthang    *
*    @date : 04 / 09 / 2021    *
*******************************/

#include <bits/stdc++.h>

using namespace std;

#define          fi  first
#define          se  second
#define  superspeed  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  file(name)  freopen(name".inp", "r", stdin);\
                     freopen(name".out", "w", stdout);

typedef                   long long  ll;
typedef pair <long long, long long>  pll;
typedef          vector <long long>  vll;

const ll Mod = 1e9 + 7;

ll B[10005], A[10005];
ll M[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

string con(ll val) {
    string x = "";
    while (val) {
        x = (char) (val % 10 + '0') + x;
        val /= 10;
    }
    while (x.size() < 2) x = '0' + x;
    return x;
}

string convert(ll val) {
    string x = "";
    while (val) {
        x = (char) (val % 10 + '0') + x;
        val /= 10;
    }
    while (x.size() < 4) x = '0' + x;
    return x;
}

ll convertfake(string x) {
    ll a = 0;
    for (ll i = 0; i < x.size(); ++i) a = a * 10 + x[i] - '0';
    return a;
}

string convert3(ll dd, ll mm, ll yy) {
    string x = "", d = con(dd), m = con(mm), y = convert(yy);
    x = d + '.' + m + '.' + y + '.';
    return x;
}

int main() {
    superspeed;
    for (ll i = 0; i <= 9999; ++i) {
        string s = convert(i);
        string d = "", m = "";
        d += s[3]; d += s[2];
        m += s[1]; m += s[0];
        ll dd = convertfake(d), mm = convertfake(m);
        if (mm <= 12 && mm > 0 && dd > 0 && dd <= M[mm]) {
            A[i] = dd;
            B[i] = mm;
            continue;
        }
        if (dd == 29 && mm == 2 && i % 4 == 0) {
            A[i] = dd;
            B[i] = mm;
            continue;
        }
        A[i] = -1;
        B[i] = 1;
    }
    ll n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        string d = s.substr(0, 2);
        string m = s.substr(3, 2);
        string y = s.substr(6, 4);
        ll x = 0;
        ll dd = convertfake(d), mm = convertfake(m), yy = convertfake(y);
        if ((mm == B[yy] && dd < A[yy]) || (mm < B[yy])) x = yy; else x = yy + 1;
        while (A[x] == -1) ++x;
        cout << convert3(A[x], B[x], x) << '\n';
    }
    return 0;
}

Compilation message

datum.cpp: In function 'll convertfake(std::string)':
datum.cpp:47:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (ll i = 0; i < x.size(); ++i) a = a * 10 + x[i] - '0';
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 11 ms 624 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 3 ms 416 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 480 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 11 ms 720 KB Output is correct