Submission #709949

# Submission time Handle Problem Language Result Execution time Memory
709949 2023-03-15T01:09:22 Z pcc Datum (COCI20_datum) C++14
50 / 50
515 ms 564 KB
#include <bits/stdc++.h>
using namespace std;

vector<tuple<int,int,int>> v;


int cnt = 0;
bool check(int y,int m,int d){
    string sy = to_string(y);
    sy = string(4-sy.size(),'0')+to_string(y);
    string sm = (m/10?"":"0")+to_string(m);
    string sd = (d/10?"":"0")+to_string(d);
    sy = sd+sm+sy;
    for(int i = 0;i<sy.size()/2;i++)if(sy[i] != sy[sy.size()-1-i])return false;
    return true;
}
void add(int year){
    int month = 1,day = 1;
    bool leap = false;
    if(year%400 == 0)leap = true;
    else if(year%100 == 0)leap = false;
    else if(year%4 == 0)leap = true;
    else leap = false;
    while(month!=13){
        if(check(year,month,day))v.push_back(make_tuple(year,month,day));
        day++;
        if(month == 2){
            if(leap&&day == 30){
                day = 1;
                month++;
            }
            else if(!leap&&day == 29){
                day = 1;
                month++;
            }
        }
        else if(month == 1||month == 3||month == 5||month==7||month==8||month == 10||month == 12){
            if(day == 32){
                day = 1;
                month++;
            }
        }
        else{
            if(day == 31){
                day = 1;
                month++;
            }
        }
    }
    return;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    auto c = clock();
    for(int i = 0;i<1e4;i++){
        add(i);
    }
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        tuple<int,int,int> tmp = make_tuple(stoi(s.substr(6,4)),stoi(s.substr(3,2)),stoi(s.substr(0,2)));
        auto k = *upper_bound(v.begin(),v.end(),tmp);
        int y = get<0>(k),m = get<1>(k),d = get<2>(k);
        string sy = to_string(y);
        sy = string(4-sy.size(),'0')+to_string(y);
        string sm = (m/10?"":"0")+to_string(m);
        string sd = (d/10?"":"0")+to_string(d);
        cout<<sd<<'.'<<sm<<'.'<<sy<<'.'<<'\n';
    }
}
/*
*/

Compilation message

datum.cpp: In function 'bool check(int, int, int)':
datum.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0;i<sy.size()/2;i++)if(sy[i] != sy[sy.size()-1-i])return false;
      |                   ~^~~~~~~~~~~~
datum.cpp: In function 'int main()':
datum.cpp:54:10: warning: unused variable 'c' [-Wunused-variable]
   54 |     auto c = clock();
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 462 ms 304 KB Output is correct
2 Correct 502 ms 460 KB Output is correct
3 Correct 480 ms 428 KB Output is correct
4 Correct 484 ms 308 KB Output is correct
5 Correct 515 ms 428 KB Output is correct
6 Correct 470 ms 432 KB Output is correct
7 Correct 479 ms 432 KB Output is correct
8 Correct 495 ms 312 KB Output is correct
9 Correct 472 ms 308 KB Output is correct
10 Correct 465 ms 564 KB Output is correct