結果
| 問題 | No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-11-06 01:03:35 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,057 bytes | 
| コンパイル時間 | 1,968 ms | 
| コンパイル使用メモリ | 173,252 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-06 17:58:30 | 
| 合計ジャッジ時間 | 2,603 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
ソースコード
# 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()];
	}
}
            
            
            
        