結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー kyunakyuna
提出日時 2018-10-28 03:20:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 54,748 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 22:21:17
合計ジャッジ時間 1,157 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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