Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: mocngaijakraila

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

Language: cpp

Time: 0.003 second

Submitted On: 2026-06-23 21:27:54

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

stack<int> s;
int m = 1;

void rec(int n) {
    if(n == 0) {
        
        while(!s.empty()) {

            cout << s.top() << ' ';
            s.pop();
        }

        cout << '\n';
        return;
    }

    if(abs(n) % 5 > 2) {

        s.push((abs(n) % 5 - 5)*m);

        rec(abs(n) / 5 + 1);
    }
    else {

        s.push((abs(n) % 5)*m);

        rec(abs(n) / 5);
    }


}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int t; cin >> t;
    
    while(t--) {
        int n; cin >> n;

        if(n == 0) {
            cout << 0 << '\n';
            continue;
        }
        if(n < 0) {
            m = -1;
        }
        else m = 1;

        rec(n);
    }

    

    return 0;
}