結果
| 問題 | No.782 マイナス進数 | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2019-01-11 22:04:48 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 2,000 ms | 
| コード長 | 705 bytes | 
| コンパイル時間 | 830 ms | 
| コンパイル使用メモリ | 73,516 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-30 07:02:37 | 
| 合計ジャッジ時間 | 2,255 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 36 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t, b;
    cin >> t >> b;
    b *= -1;
    char c[256];
    for (int h = 0; h < t; h++) {
        int n;
        cin >> n;
        if (n == 0) {
            cout << "0\n";
            continue;
        }
        int i = 255;
        c[i] = 0;
        while (n) {
            int r = n % b;
            if (r < 0) r += b;
            n -= r;
            n /= -b;
            c[--i] = r + '0';
        }
        cout << c + i << '\n';
    }
    return 0;
}
            
            
            
        