zoukankan      html  css  js  c++  java
  • B1023. 组个最小数 (20)

    给定数字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
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <string>
     6 #include <math.h>
     7 #include <algorithm>
     8 using namespace std;
     9 
    10 int main(){
    11     int a[10];
    12     for(int i=0;i<10;i++)
    13     {
    14         scanf("%d",&a[i]);
    15     } 
    16     for(int i=1;i<10;i++)
    17     {
    18         if(a[i]!=0){
    19         printf("%d",i);
    20         a[i]--;
    21         break;    
    22          }
    23     }
    24     for(int i=0;i<10;i++)
    25     {
    26         while(a[i]!=0)
    27         {
    28             printf("%d",i);
    29             a[i]--;
    30         }
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    POJ 3126 Prime Path
    POJ 2429 GCD & LCM Inverse
    POJ 2395 Out of Hay
    【Codeforces 105D】 Bag of mice
    【POJ 3071】 Football
    【POJ 2096】 Collecting Bugs
    【CQOI 2009】 余数之和
    【Codeforces 258E】 Devu and Flowers
    【SDOI 2010】 古代猪文
    【BZOJ 2982】 combination
  • 原文地址:https://www.cnblogs.com/ligen/p/4300436.html
Copyright © 2011-2022 走看看