PTA (Basic Level) 1023. Set a minimum number of

0-9 each given a number. You can arrange these numbers in any order, but must be fully utilized. The goal is to make the resulting number as small as possible (do not pay attention to the first 0). For example: Given two 0, 1 two, three 5, a 8, we get the minimum number is 10015558.

The minimum number is now given a number, please write program output can be composed of.

Input formats:

Input 10 is given a non-negative integer in a row, we have the sequence represents the number 0, the number of number 1, number 9 ....... Separated by a space between integer. The total number of 10 digits is no more than 50, and has at least one non-zero digit.

Output formats:

The smallest number in a row can be output thereof.

Sample input:
2 2 0 0 0 3 0 0 1 0
Sample output:
10015558
Thinking
  • 0 start looking from the front to put the first digit is not 0, then traverse from small to large output again, so get the minimum number of
Code
#include<bits/stdc++.h>
using namespace std;
int a[10] = {0};
int main()
{
    int n;
    for(int i=0;i<10;i++)
    {
        cin >> n;
        a[i] = n;
    }

    for(int i=1;i<10;i++)
        if(a[i] != 0)
        {
            cout << i;
            a[i]--;
            break;
        }
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<a[i];j++)
            cout << i;
    }
    return 0;
}
Quote

https://pintia.cn/problem-sets/994805260223102976/problems/994805298269634560

Guess you like

Origin www.cnblogs.com/MartinLwx/p/11626784.html