結果

問題 No.782 マイナス進数
ユーザー face4
提出日時 2019-01-11 22:13:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 585 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 67,968 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-30 08:10:57
合計ジャッジ時間 2,136 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int p(int i, int j){
    int ret = 1;
    while(j-- > 0)  ret *= i;
    return ret;
}

int main(){
    int t, b, n;
    cin >> t >> b;

    while(t-- > 0){
        string res = "";
        cin >> n;

        int cnt = 0;
        while(n){
            int tmp = n%(p(-b, cnt+1));
            if(tmp < 0) tmp -= b;
            string add{(char)('0'+tmp)};
            res += add;
            n -= tmp;
            n /= b;
        }

        reverse(res.begin(), res.end());

        cout << res << endl;
    }

    return 0;
}
0