1023. Minimum number of groups (20)
Several numbers are given from 0 to 9. You can arrange these 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 cannot be the first). For example: given two 0s, two 1s, three 5s, and an 8, the smallest number we can get is 10015558.
Given a number, write a program to output the smallest number that can be formed.
Input format:
Each input contains 1 test case. Each test case gives 10 non-negative integers in a row, in the order that we have the number 0, the number 1, ... the number 9. Separate integers with a space. The total number of 10 numbers does not exceed 50, and there is at least one non-zero number.
Output format:
Print the smallest number that can be formed on a line.
Input sample:2 2 0 0 0 3 0 0 1 0Sample output:
10015558
#include<cstdio> using namespace std; int main(){ int arr[10]; for(int i = 0; i < 10; i++)scanf("%d", &arr[i]); int len = 1; while(arr[len++] == 0); len--; arr[len]--; printf("%d", len); for(int i = 0; i < 10; i++){ for(int j = 0; j < arr[i]; j++) printf("%d", i); } return 0; }