結果

問題 No.593 4進FizzBuzz
ユーザー cormorancormoran
提出日時 2017-11-10 22:49:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 168,516 KB
実行使用メモリ 7,400 KB
最終ジャッジ日時 2024-11-24 13:05:35
合計ジャッジ時間 3,552 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()

class Solver {
  public:
    bool solve() {
        string s; cin >> s;
        reverse(all(s));
        int base = 1;
        int ans = 0;
        for(char c : s) {
            int cc = c - '0';
            ans += base * cc;
            base = (base * 4) % 15;
            ans %= 15;
        }
        reverse(all(s));
        cout << (ans == 0 ? "FizzBuzz" : ans % 3 == 0 ? "Fizz" : ans % 5 == 0 ? "Buzz" : s) << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0