以下の内容はhttps://blog.hamayanhamayan.com/entry/2021/05/05/162532より取得しました。


Hexatridecimal [第五回 アルゴリズム実技検定 C]

https://atcoder.jp/contests/past202012-open/tasks/past202012_c

解説

https://atcoder.jp/contests/past202012-open/submissions/22280794

10進数から他の進法への変換アルゴリズムをそのまま適用する。
36進数になるので、36で割った余りを下から文字列化していく。
「進数変換 やり方」あたりでググればより良い文献を見つけることができるだろう。

実装によりけりであるが、N=0がコーナーケースとなりうる。
自分の場合はそうだったので、別途扱って出力している。

int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    if (N == 0) {
        cout << 0 << endl;
        return;
    }

    string ans = "";
    while (0 < N) {

        int d = N % 36;
        N /= 36;

        if (0 <= d && d < 10) ans = char('0' + d) + ans;
        else ans = char('A' + d - 10) + ans;
    }
    cout << ans << endl;
}



以上の内容はhttps://blog.hamayanhamayan.com/entry/2021/05/05/162532より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14