当前位置:网站首页>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;
}
边栏推荐
- Deep Qt5 signal slot new syntax
- Be diligent in talking about what sidelines you can do now
- 标准对话框 QMessageBox
- Mysql表的约束
- Detailed description of binary search tree
- 牛客剑指offer--JZ12 矩阵中的路径
- JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
- Basic operation of vim
- 抽卡程序模拟
- Advantages of smart exhibition hall design and applicable industry analysis
猜你喜欢

What if Photoshop prompts that the temporary storage disk is full? How to solve the problem that PS temporary storage disk is full?

Read write separation and master-slave synchronization

OFDM 16 lecture 2-ofdm and the DFT

QT 菜单栏、工具栏和状态栏

Review of various historical versions of Photoshop and system requirements

Tcp server是如何一个端口处理多个客户端连接的(一对一还是一对多)

标准对话框 QMessageBox

一、MySQL基础

Introduction to dynamic memory functions (malloc free calloc realloc)

Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
随机推荐
Use of collection framework
Event filter
Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
Error: cannot read properties of undefined (reading 'then')
QT 菜单栏、工具栏和状态栏
动态内存函数的介绍(malloc free calloc realloc)
Detailed explanation of pointer constant and constant pointer
Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
Differences among left join, inner join and right join
[Niuke discussion area] Chapter 7: building safe and efficient enterprise services
二、MySQL高级
事件的接受与忽略
[untitled] I is circularly accumulated under certain conditions. The condition is usually the length of the loop array. When it exceeds the length, the loop will stop. Because the object cannot judge
There is no need to install CUDA and cudnn manually. You can install tensorflow GPU through a one-line program. Take tensorflow gpu2.0.0, cuda10.0, cudnn7.6.5 as examples
事件(event)
老子云携手福昕鲲鹏,首次实现3D OFD三维版式文档的重大突破
一、MySQL基础
"Photoshop2021 tutorial" adjust the picture to different aspect ratio
JVM上篇:内存与垃圾回收篇十一--执行引擎
Introduction to dynamic memory functions (malloc free calloc realloc)