結果

問題 No.499 7進数変換
ユーザー @abcde
提出日時 2019-02-23 10:19:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 980 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 164,928 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 20:59:27
合計ジャッジ時間 2,360 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    
    // 1. 入力情報取得.
    LL N;
    cin >> N;
    
    // 2. 7進数に変換.
    // 2-1. N が 0 なら終了.
    if(N == 0){
        cout << 0 << endl;
        return 0;
    }
    
    // 2-2. N が 0 より大きい場合.
    // -> N を ひたすら 7 で割っていく.
    map<LL, LL> ans;
    while(N){
        LL q = N / 7;
        LL r = N % 7;
        ans[q] = r;
        N /= 7;
    }
    // for(auto &p : ans) cout << p.first << " " << p.second << endl;
    // [入力例]
    // 1000000000
    // 
    // [出力例(debug版)]
    // 0 3
    // 3 3
    // 24 5
    // 173 3
    // 1214 1
    // 8499 6
    // 59499 0
    // 416493 0
    // 2915451 6
    // 20408163 1
    // 142857142 6
    // -> 上から順に余りを取ってきて, 33531600616 を抽出できた.

    // 3. 出力.
    for(auto &p : ans) cout << p.second;
    cout << endl;
    return 0;
    
}
0