結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー alcheminalchemin
提出日時 2019-09-18 11:03:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 169,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 04:53:57
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

bool IsLeapYear(int year);

int main() {
    string s;
    
    cin >> s;
    
    string tmp = "";
    vector<string> v;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '/') {
            v.push_back(tmp);
            tmp = "";
        } else {
            tmp += s[i];    
        }
    }
    v.push_back(tmp);
    
    int year = stoi(v[0]);
    int month = stoi(v[1]);
    int day = stoi(v[2]) + 2;
    
    if (month == 2) {
        if (IsLeapYear(year)) {
            if (day > 29) {
                month++;
                day -= 29;
            }
        } else {
            if (day > 28) {
                month++;
                day -= 28;
            }
        }
    } else if ((month == 4 || month == 6 || month == 9 || month == 11) &&
                day > 30) {
        month++;
        day -= 30;
    } else if (day > 31) {
        if (month == 12) {
            year++;
        }
        month = (month + 1) % 12;
        day -= 31;
    }
    
    cout << year << "/";
    cout << setfill('0') << std::right << setw(2) << month << "/" ;
    cout << setfill('0') << std::right << setw(2) << day << endl;
    
    return 0;
}

bool IsLeapYear (int year) {
    bool ret = false;
    if (year % 4 == 0) {
        if (year % 100 == 0) {
            if (year % 400 == 0) {
                ret = true;
            }
        } else {
            ret = true;
        }
    }
    
    return ret;
}
0