結果

問題 No.423 ハムスター語初級(数詞)
ユーザー weaken
提出日時 2021-05-22 13:42:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 946 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 195,492 KB
最終ジャッジ日時 2025-01-21 17:13:09
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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