結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー f843nmfwisfeuwf843nmfwisfeuw
提出日時 2020-07-25 16:35:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,017 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 93,640 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 15:39:30
合計ジャッジ時間 1,893 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int lastDayOfMonth(int, int)’ 内:
main.cpp:55:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   55 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>

using namespace std;

int lastDayOfMonth(int year, int month) {

    if (month == 2) {
        if (year % 400 == 0) {
            return 29;
        } else if (year % 100 == 0) {
            return 28;
        } else if (year % 4 == 0) {
            return 29;
        } else {
            return 28;
        }
    } else {
        switch (month) {
            case 1:
                return 31;
            case 3:
                return 31;
            case 4:
                return 30;
            case 5:
                return 31;
            case 6:
                return 30;
            case 7:
                return 31;
            case 8:
                return 31;
            case 9:
                return 30;
            case 10:
                return 31;
            case 11:
                return 30;
            case 12:
                return 31;

        }
    }
}

int extract(string s) {
    if (s[0] == '0') {
        return s[1] - '0';
    } else {
        return stoi(s);
    }
}

string insert(int n) {
    string s;
    if (n <= 9) {
        s += '0';
        s += to_string(n);
        return s;
    } else {
        return to_string(n);
    }
}

int main() {

    string s;
    cin >> s;
    int YYYY = extract(s.substr(0, 4));
    int MM = extract(s.substr(5, 2));
    int DD = extract(s.substr(8, 2));

    int targetDay = DD + 2;

    string result;

    if (targetDay <= lastDayOfMonth(YYYY, MM)) {
    } else {
        targetDay = targetDay - lastDayOfMonth(YYYY, MM);
        if (MM == 12) {
            MM = 1;
            YYYY += 1;
        } else {
            MM += 1;
        }
    }

    result += insert(YYYY);
    result += "/";
    result += insert(MM);
    result += "/";
    result += insert(targetDay);

    cout << result << endl;

    return 0;
}
0