結果

問題 No.782 マイナス進数
ユーザー kyuna
提出日時 2019-07-19 11:56:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 73,912 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 00:02:53
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template<typename T>
vector<T> convert_base(T x, T base) {
    if (x == 0) return {0};
    vector<T> ret;
    while (x) {
        T r = x % base;
        if (r < 0) r -= base;
        x = (x - r) / base;
        ret.emplace_back(r);
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    int t, b; cin >> t >> b;
    while (t--) {
        int n; cin >> n;
        for (int x: convert_base(n, b)) cout << x;
        cout << endl;
    }
    return 0;
}
0