結果

問題 No.593 4進FizzBuzz
ユーザー kichirb3kichirb3
提出日時 2018-03-17 15:36:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 64,568 KB
実行使用メモリ 7,224 KB
最終ジャッジ日時 2023-08-25 15:40:08
合計ジャッジ時間 2,972 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 10 ms
7,036 KB
testcase_17 AC 10 ms
6,924 KB
testcase_18 AC 10 ms
6,984 KB
testcase_19 AC 10 ms
7,224 KB
testcase_20 AC 10 ms
6,988 KB
testcase_21 AC 10 ms
7,056 KB
testcase_22 AC 10 ms
6,928 KB
testcase_23 AC 9 ms
6,928 KB
testcase_24 AC 10 ms
7,044 KB
testcase_25 AC 10 ms
7,148 KB
testcase_26 AC 10 ms
6,984 KB
testcase_27 AC 11 ms
7,048 KB
testcase_28 AC 9 ms
6,976 KB
testcase_29 AC 10 ms
7,224 KB
testcase_30 AC 9 ms
6,924 KB
testcase_31 AC 9 ms
6,936 KB
testcase_32 AC 10 ms
6,928 KB
testcase_33 AC 10 ms
7,052 KB
testcase_34 AC 9 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.593 4進FizzBuzz
// https://yukicoder.me/problems/no/593
//
#include <iostream>
#include <string>
using namespace std;

string solve(string &&s);


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    string ans = solve(move(s));
    cout << ans << endl;
}

string solve(string &&s) {
    string ans = s;

    int digit = s.size();
    int sign = 1;
    if (digit % 2 == 0)
        sign = -1;

    int fizz = 0;
    int buzz = 0;

    for (char c: s) {
        int n = c - '0';
        fizz += n;
        buzz += n * sign;
        sign *= -1;
    }

    if (fizz % 3 == 0) {
        if (buzz % 5 == 0)
            ans = "FizzBuzz";
        else
            ans = "Fizz";
    } else if (buzz % 5 == 0)
        ans = "Buzz";
    return ans;
}
0