結果
問題 |
No.593 4進FizzBuzz
|
ユーザー |
![]() |
提出日時 | 2018-03-17 15:36:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 805 bytes |
コンパイル時間 | 664 ms |
コンパイル使用メモリ | 65,280 KB |
実行使用メモリ | 7,276 KB |
最終ジャッジ日時 | 2024-12-24 00:26:28 |
合計ジャッジ時間 | 2,563 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
// 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; }