PAT Basic 1023 set a minimum number (20 minutes)

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

 

#include <iostream>
using namespace std;
int main(){
    int val[10],tmp;
    for(int i=0;i<10;i++){
        cin>>val[i];
    }
    for(int i=1;i<10;i++){
        if(val[i]!=0){
            val[i]--;
            cout<<i;
            break;
        }
    }
    for(int i=0;i<10;i++){
        if(val[i]!=0){
            while(val[i]--) cout<<i;
        }
    }
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11355710.html