結果

問題 No.423 ハムスター語初級(数詞)
ユーザー weakenweaken
提出日時 2021-05-22 13:42:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 946 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 197,720 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 17:38:30
合計ジャッジ時間 2,632 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

void solve() {
  string n;
  cin >> n;

  if (n.size() == 0) {
    cout << "ham" << '\n';
    return;
  }

  string bin{};
  for (size_t i = 0; i < n.size();) {
    if (n.substr(i, 4) == "hamu") {
      bin += "1";
      i += 4;
    } else {
      bin += "0";
      i += 3;
    }
  }

  // bin to int
  int num{0};
  int exp{(int)bin.size() - 1};
  for (const auto b : bin) {
    if (b == '1') num += (int)pow(2, exp);
    exp--;
  }

  num *= 2;
  auto binary = bitset<10>(num);
  bool firstHamu = false;

  for (int i = (int)binary.size() - 1; i >= 0; i--) {
    if (binary[i]) {
      cout << "hamu";
      firstHamu = true;
    } else if (!binary[i] && firstHamu == true) {
      cout << "ham";
    }
  }
  cout << '\n';
}

int main() {
  FastIO;
  solve();
  return 0;
}
0