結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー ngng628ngng628
提出日時 2021-11-06 01:03:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 171,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-06 14:53:22
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <bits/stdc++.h>
using namespace std;

string base_convert(string n, int from, int to) {
   int dec = stoll(n, nullptr, from);
   if (dec == 0) return "0";
   string res;
   while (dec) {
      int d = dec % to;
      if (0 <= d and d <= 9) res += d + '0';
      else res += d - 10 + 'A';
      dec /= to;
   }
   reverse(res.begin(), res.end());
   return res;
}

int main() {
	string s;
	cin >> s;

	string bin;
	for (char c : s) {
		bitset<4> b(c - 'A' + 10);
		bin.append(b.to_string());
	}

	while (bin.length() % 3 != 0) bin = "0" + bin;

	string oct;
	for (size_t i = 0; i + 2 < bin.length(); i += 3) {
		string sub = bin.substr(i, 3);
		char c = base_convert(sub, 2, 8)[0];
		oct.push_back(c);
	}

	int mx = 0;
	for (char c = '0'; c <= '7'; ++c) {
		mx = max(mx, int(count(oct.begin(), oct.end(), c)));
	}

	vector<char> ans;
	for (char c = '0'; c <= '7'; ++c) {
		if (mx == int(count(oct.begin(), oct.end(), c))) {
			ans.push_back(c);
		}
	}

	for (size_t i = 0; i < ans.size(); ++i) {
		cout << ans[i] << " \n"[i + 1 == ans.size()];
	}
}
0