topic:
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
Code:
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int main(){ int n,m; int b[11] = {0}; for(int i=0;i<10;i++){ scanf("%d",&b[i]); } for(int i=1;i<10;i++){ if(b[i] != 0){ b[i] --;//After outputting a number, it should be subtracted printf("%d",i); break; } } for(int i=0;i<10;i++){ for(int j=0;j<b[i];j++){ printf("%d",i); } } return 0; }