当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Svn usage details

Error: cannot read properties of undefined (reading 'then')

Jmeter 界面如何汉化?

Sunset red warm tone tinting filter LUTS preset sunset LUTS 1

Inspiration from "flying man" Jordan! Another "arena" opened by O'Neill

支付流程如何测试?

《Robust and Precise Vehicle Localization based on Multi-sensor Fusionin Diverse City Scenes》翻译

JVM Part 1: memory and garbage collection part 14 -- garbage collector

pyside2____1.安装和案列

Could not autowire.No beans of ‘userMapper‘ type found.
随机推荐
Mysql表的约束
B1031 查验身份证
Solution and principle analysis of feign call missing request header
ssm框架整合
Use ngrok for intranet penetration
How idea creates a groovy project (explain in detail with pictures and texts)
MQ message queue is used to design the high concurrency of the order placing process, the generation scenarios and solutions of message squeeze, message loss and message repetition
Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
Counting Nodes in a Binary Search Tree
"Photoshop2021 introductory tutorial" flatten "perspective images
Acceptance and neglect of events
Hiding skills of Photoshop clipping tool
JVM上篇:内存与垃圾回收篇八--运行时数据区-方法区
文件处理(IO)
知识点总结(一)
微淼联合创始人孙延芳:以合规为第一要义,做财商教育“正规军”
What is the future development direction of software testing engineers?
How does PS import LUT presets? Photoshop import LUT color preset tutorial
35. Scroll