Q:

Find minimum number of binary-decimals for a given input -n.

A number is called as binary-decimal if all the digits in the number should be either ‘1’ or ‘0’. Any number can be written as a sum of binary-decimals. Our task is to find the minimum number of binary-decimals to represent a number.
Input  : 32 
Output : 10 11 11
Input  : 120
Output : 10 110
What could be an efficient solution to this?

A:

take for example
54321 the answer is 
11111
11110
11100
11000
10000
so consider it as a m*n matrix where m is maximum value of the digit in given number and n is number of digits. Then fill the columns with number of 1's equal to the value of digit corresponding to that column and rest with 0's.
        #include<iostream>

        using namespace std;
        int max(int arr[],int c)
        {
            int max=arr[0];
            for(int i=1;i<c;i++){
                if(arr[i]>max){
                    max=arr[i];
                }
            }
            return max;
        }
        int main() {
            int n,x,c=0,i=0,j=0;
            cin>>n;
            x=n;
            while(n!=0){
                n=n/10;
                c++;
            }
            int *a=new int[c];

            while(x!=0){
                a[i]=x%10;
                x=x/10;
                i++;
            }
            int r=max(a,c);
            int ans[r][c];
            for(int i=0;i<c;i++)
            {
                for(int j=0;j<r;j++)
                {
                    if(a[c-i-1]!=0){
                        ans[j][i]=1;
                        a[c-i-1]--;
                    }
                    else
                        ans[j][i]=0;
                }
            }
            for(i=0;i<r;i++){
                for(j=0;j<c;j++){
                    cout<<ans[i][j];
                }
                cout<<"\n";
            }

            }

