結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー kyuna
提出日時 2018-10-28 03:20:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 55,312 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-19 06:58:12
合計ジャッジ時間 1,133 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>      // assert
using namespace std;

bool is_leap(int y) {
    if (y % 400 == 0) return true;
    if (y % 100 == 0) return false;
    if (y % 4 == 0)   return true;
    return false;
}

int get_days_in_month(int y, int m) {
    assert(m >= 1 && m <= 12);
    int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (m == 2 && is_leap(y)) {
        return days[2] + 1;
    }
    return days[m];
}

class MyDate {
public:
    int day;
    int month;
    int year;

    MyDate(int y, int m, int d) {
        year = y;
        month = m;
        day = d;
    }

    MyDate tomorrow() {
        int ty = year, tm = month, td = day;

        td++;
        if (td > get_days_in_month(year, month)) {
            td = 1;
            tm++;
            if (tm > 12) {
                ty++;
                tm = 1;
            }
        }
        return MyDate(ty, tm, td);
    }
};

int main() {
    int a, b, c;
    char d;
    cin >> a >> d >> b >> d >> c;
    MyDate date(a, b, c);
    date = date.tomorrow();
    date = date.tomorrow();
    cout << date.year                                  << "/"
         << (date.month < 10 ? "0" : "") << date.month << "/"
         << (date.day   < 10 ? "0" : "") << date.day   << endl;
}
0