Topic describes

Given a number of numbers from 0 to 9. You can arrange the numbers in any order, but you must use them all. The goal is to make the resulting number as small as possible (note that 0 is not the first digit). For example, given two zeros, two ones, three fives, and one eight, the smallest number we can get is 10015558.

Given a number, write a program to output the smallest number that can be composed.

Input format: Input gives 10 non-negative integers in a row, in order to indicate that we have the numbers 0, 1,… The number of 9’s. Integers are separated by a space. The total number of 10 digits cannot exceed 50, and there must be at least one non-0 digit.

Output format: Outputs the smallest number that can be formed in a line.

Input example: 2 2 00 0 3 001 0 Output example: 10015558

Thought analysis

Store the numbers from 0 to 9 in array A [I], first printing the first non-zero number and then printing 0 to the largest number.

AC code

#include <iostream>
using namespace std;
int main()
{
	int a[10];
	for(int i=0; i<10; i++) cin>>a[i];for(int i=1; i<10; i++) {if(a[i]! =0)
        {
            cout<<i;
            a[i]--;
            break; }}for(int i=0; i<10; i++)while(a[i]--)
		cout<<i;
	return 0;
}
Copy the code

Conclusion comprehension

Brush topic in persistence, make persistent efforts! 😉