結果

問題 No.188 HAPPY DAY
ユーザー gamenerdDAIgamenerdDAI
提出日時 2018-08-29 00:11:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,098 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 143,716 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-25 15:30:55
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int cnt_happy_day (int month);
int digit_sum (int n);

int main () {

    int ans = 0;

    for (int month = 1; month <= 12; month++) {
        ans += cnt_happy_day(month);
    }

    cout << ans << endl;

    return 0;
}

int cnt_happy_day (int month) {

    int cnt = 0;

    switch (month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            for (int day = 1; day <= 31; day++) {
                if (month == digit_sum(day)) cnt++;
            }
            break;

        case 4:
        case 6:
        case 9:
        case 11:
            for (int day = 1; day <= 30; day++) {
                if (month == digit_sum(day)) cnt++;
            }
            break;

        case 2:
            for (int day = 1; day <= 28; day++) {
                if (month == digit_sum(day)) cnt++;
            }
            break;
    }

    return cnt;
}

int digit_sum (int n) {

    int sum = 0;

    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}
0