結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー yorry2101yorry2101
提出日時 2023-06-15 16:05:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 2,440 ms
コンパイル使用メモリ 204,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 20:15:16
合計ジャッジ時間 3,900 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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