PAT-B 1023. Min number of groups (20), pat-b1023

Source: Internet
Author: User

PAT-B 1023. Min number of groups (20), pat-b1023
1023. Minimum number of groups (20)

The number 0-9 is given. You can arrange these numbers in any order, but they must all be used. The goal is to make the final number as small as possible (note that 0 cannot be the first place ). For example, given two 0 s, two 1 s, three 5 S, and one 8 s, the minimum number we get is 10015558.

Given a number, write a program to output the smallest number.

Input Format:

Each input contains one test case. Each test case contains 10 non-negative integers in one row, indicating that we have numbers 0, numbers 1 ,...... The number of digits 9. An integer is separated by a space. The total number of 10 numbers cannot exceed 50, and at least one number is not 0.

Output Format:

Output the smallest number in a row.

Input example:
2 2 0 0 0 3 0 0 1 0
Output example:
10015558




Train of Thought Analysis: Put the 10 numbers in an array first, take out the smallest number (except 0), and mark it. And then output in ascending order.

 1 #include <cstdio> 2 int main() { 3     int a[10]; 4     int i; 5     for( i = 0; i < 10; i++ ) { 6         scanf( "%d", &a[i] ); 7     } 8  9     int min;10     for( i = 0; i < 10; i++ ) {11         if( i != 0 && a[i] != 0 ) {12             min = i;13             break;14         }15     }16     printf( "%d", min );17     a[min]--;18     for( i = 0; i < 10; i++ ) {19         for( ; a[i] > 0; a[i]-- ) {20             printf( "%d", i );21         }22     }23     return 0;24 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.