Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: angpangSK

Problemset: เลขฐานเบญจภาคได้ดุล

Language: cpp

Time: 0.005 second

Submitted On: 2025-09-26 08:54:10

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

string DecimalToBalancedQuinary(int n) {
    if (n == 0) return "0";

    string res = "";
    while (n != 0) {
        int r = n % 5;
        n /= 5;

        if (r > 2) {
            r -= 5;
            n += 1;
        } else if (r < -2) {
            r += 5;
            n -= 1;
        }

        if (r == -2) res += '=';
        else if (r == -1) res += '-';
        else res += char('0' + r);
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        string ans = DecimalToBalancedQuinary(a[i]);
        for (int j = 0; j < ans.size(); j++) {
            if (ans[j] == '-') cout << "-1 ";
            else if (ans[j] == '=') cout << "-2 ";
            else cout << ans[j] << " ";
        }
        cout << endl;
    }
    return 0;
}