結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー yorry2101
提出日時 2023-06-15 16:05:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 201,272 KB
最終ジャッジ日時 2025-02-14 03:01:12
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    string bstr;
    for (int i = (int)s.size()-1; i >= 0; i--) {
        bitset<4> b(stoi(s.substr(i, 1), nullptr, 16));
        bstr = b.to_string() + bstr;
    }
    
    while (bstr.size()%3 != 0) {
        bstr = "0" + bstr;
    }
    string ostr;
    for (int i = (int)bstr.size()-3; i >= 0; i -= 3) {
        bitset<3> o(stoi(bstr.substr(i, 3), nullptr, 2));
        ostr = to_string(o.to_ulong()) + ostr;
    }
    
    //take.max
    vector<int> aoct(8);
    for (int i = 0; i < (int)ostr.size(); i++) {
        aoct[stoi(ostr.substr(i, 1))]++;
    }
    
    int mxs = -1;
    vector<int> ans;
    for (int i = 0; i < 8; i++) {
        if (aoct[i] > mxs) {
            ans.resize(0);
            mxs = aoct[i];
            ans.push_back(i);
        }
        else if (aoct[i] == mxs) {
            ans.push_back(i);
        }
    }
    for (int i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << ((i == (int)ans.size()-1) ? "\n" : " ");
    }
}
0