답안 #391526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391526 2021-04-19T08:32:09 Z phathnv Datum (COCI20_datum) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "DATUM"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

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

string toString(int x, int len){
    string res;
    for(int i = 1; i <= len; i++){
        res = (char) (x % 10 + '0') + res;
        x /= 10;
    }
    return res;
}

struct date{
    int d, m, y;
    date(int _d = 0, int _m = 0, int _y = 0){
        d = _d;
        m = _m;
        y = _y;
    }
    date(string &s){
        d = (s[0] - '0') * 10 + (s[1] - '0');
        m = (s[3] - '0') * 10 + (s[4] - '0');
        y = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');
    }
    bool leapYear(){
        return (y % 4 == 0);
    }
    bool isValid(){
        if (d < 1 || m < 1 || 12 < m)
            return 0;
        if (m != 2 && d <= dayInMonth[m])
            return 1;
        if (d <= dayInMonth[2] + leapYear())
            return 1;
        return 0;
    }
    bool isPalindromic(){
        string s = toString(d, 2) + toString(m, 2) + toString(y, 4);
        string revS = s;
        reverse(revS.begin(), revS.end());
        return (s == revS);
    }
    bool check(){
        return (isValid() && isPalinromic());
    }
    void print(){
        cout << toString(d, 2) << '.' << toString(m, 2) << '.' << toString(y, 4) << ".\n";
    }
};

bool operator < (const date &a, const date &b){
    if (a.y != b.y)
        return a.y < b.y;
    if (a.m != b.m)
        return a.m < b.m;
    return a.d < b.d;
}

int n;
vector <date> palinromicDays;

void readInput(){
    scanf("%d", &n);
}

void solve(){
    for(int a = 0; a <= 3; a++)
        for(int b = 0; b <= 9; b++)
            for(int c = 0; c <= 1; c++)
                for(int d = 0; d <= 9; d++){
                    date tmp(a * 10 + b, c * 10 + d, d * 1000 + c * 100 + b * 10 + a);
                    if (tmp.check())
                        palinromicDays.push_back(tmp);
                }
    sort(palinromicDays.begin(), palinromicDays.end());
    while (n--){
        string s;
        cin >> s;
        date q(s);
        (*upper_bound(palinromicDays.begin(), palinromicDays.end(), q)).print();
    }
}

int main(){
    readInput();
    solve();
    return 0;
}

Compilation message

datum.cpp: In member function 'bool date::check()':
datum.cpp:55:30: error: 'isPalinromic' was not declared in this scope; did you mean 'isPalindromic'?
   55 |         return (isValid() && isPalinromic());
      |                              ^~~~~~~~~~~~
      |                              isPalindromic
datum.cpp: In function 'void readInput()':
datum.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~