結果
| 問題 |
No.593 4進FizzBuzz
|
| ユーザー |
hanorver
|
| 提出日時 | 2017-11-26 20:48:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,336 bytes |
| コンパイル時間 | 1,089 ms |
| コンパイル使用メモリ | 82,888 KB |
| 実行使用メモリ | 14,460 KB |
| 最終ジャッジ日時 | 2024-11-27 11:46:12 |
| 合計ジャッジ時間 | 11,498 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 9 TLE * 2 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>
int main()
{
std::string s, s2;
std::cin >> s;
s2 = s;
int count3 = 0, count2 = 0, count1 = 0, count0 = 0;
for (size_t i = 0; i < s.length(); i++)
{
if (s[i] == '3') count3++;
else if (s[i] == '2') count2++;
else if (s[i] == '1') count1++;
else count0++;
}
while (count2 != 0 && count1 != 0) {
count3++;
count2--;
count1--;
}
bool divide3 = false, divide5 = false;
if (count2 == 0 && count1 == 0) {
divide3 = true;
}
for (size_t i = 0; i < s.length(); i++)
{
if (s[i] == '0') continue;
size_t j = i + 1;
while (j < s.length())
{
if (s[j] == '0') {
j += 2;
continue;
}
if (s[j] == '3') {
s[j] = '2';
}
else if (s[j] == '2') {
s[j] = '1';
}
else {
s[j] = '0';
}
if (s[i] == '3') {
s[i] = '2';
}
else if (s[i] == '2'){
s[i] = '1';
}
else {
s[i] = '0';
break;
}
}
}
divide5 = true;
for (size_t i = 0; i < s.length(); i++)
{
if (s[i] != '0') divide5 = false;
}
if (divide3) {
std::cout << "Fizz";
}
if (divide5) {
std::cout << "Buzz" << std::endl;
}
if (!divide3 && !divide5) {
std::cout << s2 << std::endl;
}
return 0;
}
hanorver