当前位置:网站首页>B1023 组个最小数
B1023 组个最小数
2022-07-27 05:01:00 【叶辰 .】
1023 组个最小数 (20 分)
给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558。
现给定数字,请编写程序输出能够组成的最小的数。
输入格式:
输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0、数字 1、……数字 9 的个数。整数间用一个空格分隔。10 个数字的总个数不超过 50,且至少拥有 1 个非 0 的数字。
输出格式:
在一行中输出能够组成的最小的数。
输入样例
2 2 0 0 0 3 0 0 1 0
输出样例
10015558
题目分析:
- 记录数字的出现次数
- 注意需要除了0之外最小的数字作为首位,并记次数减一
代码如下:
#include <bits/stdc++.h>
using namespace std;
int main(){
int a[10];
for(int i=0;i<10;i++){
cin>>a[i];
}
for(int i=1;i<10;i++){
if(a[i]!=0){
cout<<i;
a[i]--;
break;
}
}
for(int i=0;i<10;i++){
for(int j=0;j<a[i];j++){
cout<<i;
}
}
return 0;
}
边栏推荐
- A math problem cost the chip giant $500million
- 事件总结-常用总结
- How idea creates a groovy project (explain in detail with pictures and texts)
- 微淼联合创始人孙延芳:以合规为第一要义,做财商教育“正规军”
- MySQL storage engine and its differences
- 智慧展厅设计的优势及适用行业分析
- Solution to Dlib installation failure
- Network protocol details: IP
- DBUtils
- JVM上篇:内存与垃圾回收篇十二--StringTable
猜你喜欢
随机推荐
Detailed description of polymorphism
Introduction to Web Framework
Interface and abstract class / method learning demo
Complete Binary Tree
35. Scroll
对话框简介
Final Cut Pro Chinese tutorial (1) basic understanding of Final Cut Pro
Network protocol details: IP
事件(event)
Acticiti中startProcessInstanceByKey方法在variable表中的如何存储
How do I reset Photoshop preferences? PS method of resetting preferences
Basic operation of vim
Quoted popular explanation
OFDM 16 lecture 2-ofdm and the DFT
JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
Constraints of MySQL table
二、MySQL高级
DBUtils
Why is count (*) slow
JVM Part 1: memory and garbage collection part 14 -- garbage collector









