PAT (Basic level) practise (Chinese) 1023. Minimum number of groups (20)

Source: Internet
Author: User

1023. Group minimum (20) time limit of three MS
Memory Limit 65536 KB
Code length limit 8000 B
Procedures for the award of questions StandardAuthor CAO, Peng

Given a number of 0-9 each. You can arrange these numbers in any order, but you must use them all. The goal is to make the last available number as small as possible (note that 0 cannot do the first). For example: Given two x 0, two 1, three 5, and one 8, the smallest number we get is 10015558.

Now given the number, write the minimum number that the program output can consist of.

Input format:

Each input consists of 1 test cases. Each test case gives 10 nonnegative integers in a row, which means we have the number 0, the number 1 、...... Number of digits 9. Separate integers with a single space. The total number of 10 digits does not exceed 50 and has at least 1 non-0 digits.

Output format:

Outputs the smallest number that can be composed in a row.

Input Sample:
2 2 0 0 0 3 0 0 1 0
Sample output:
10015558
Problem Solving Ideas:
• Use array a[0],.. A[9] Storage 0 ... 9 Number of occurrences
• The first number of digits must not be zero, while the minimum number is required, i.e. the output is the smallest non-zero, and the number of times is reduced by one
• Output All "0".
• Output All numbers by the number of times since 1, starting from small to large
#include <iostream>using namespace Std;int main () {int a[10], I, J;for (i=0; i<10; i++) cin >> A[i];//a[i] Kee The number of occurrences of 0 to 9 for (I=1; i<10; i++)//output of the smallest non-zero if (A[i]) {cout << i;//output after the number of times to terminate the loop A[i]--;break;} for (i=0; i<a[0]; i++) cout << "0";//Output all 0 for (i=1; i<10; i++) for (j=0; j<a[i]; j + +) cout << i;/ /from small to large by its number of outputs all cout << Endl;return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PAT (Basic level) practise (Chinese) 1023. Minimum number of groups (20)

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.