1023. 组个最小数 (20)

389 篇文章 1 订阅
72 篇文章 0 订阅

1023. 组个最小数 (20)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B
判题程序 Standard 作者 CAO, Peng

给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。
现给定数字,请编写程序输出能够组成的最小的数。
输入格式:
每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个数。整数间用一个空格分隔。10个数字的总个数不超过50,且至少拥有1个非0的数字。
输出格式:
在一行中输出能够组成的最小的数。
输入样例:
2 2 0 0 0 3 0 0 1 0
输出样例:
10015558

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;



int main()
{
#ifdef _DEBUG
    //freopen("data.txt", "r+", stdin);
    fstream cin("data.txt");
#endif // _DEBUG
    const int MaxN = 100;
    char Num[MaxN], bit[] = { '0','1','2','3','4','5','6','7','8','9' };
    string tmp = "";
    int index = 0, N, b = 0, i;
    while (cin >> N)//输入
    {
        for (int i = 0; i < N; ++i)
            Num[index++] = bit[b];
        ++b;
    }

    sort(Num, Num + index);

    for (i = 0; Num[i] == '0';)//找第一个非零的字符
        tmp += Num[i++];

    printf("%c%s", Num[i++], tmp.c_str());
    while (i < index)
        printf("%c", Num[i++]);


#ifdef _DEBUG
    cin.close();
#ifndef _CODEBLOCKS
    system("pause");
#endif // !_CODEBLOCKS
#endif // _DEBUG

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值