当前位置:网站首页>Pat class B 1023 minimum decimals
Pat class B 1023 minimum decimals
2022-06-23 05:57:00 【Octopus bro】
1023. Group a minimum number (20)
Given number 0-9 There are several of them . You can arrange these numbers in any order , But all must be used . The goal is to make the final number as small as possible ( Be careful 0 Can't be the first ). for example : Given two 0, Two 1, Three 5, One 8, The smallest number we get is 10015558.
Now give the number , Please write a program to output the smallest number that can be composed .
Input format :
Each input contains 1 Test cases . Each test case is given on one line 10 Nonnegative integers , Order means we have numbers 0、 Numbers 1、…… Numbers 9 The number of . Integers are separated by a space .10 The total number of numbers does not exceed 50, And at least have 1 A non 0 The number of .
Output format :
Output the smallest number that can be composed in one line .
sample input :2 2 0 0 0 3 0 0 1 0sample output :
10015558
Ideas : First output a minimum non-zero position , Then judge whether there is 0, If you have any 0 Then output all 0, Then output all non-zero bits in ascending order
One 、 Starting variable
1.count【10】, Statistics 0-9 The number of
2.flag, Used to mark whether there is 0
Two 、 operation
1. Statistics 0-9 Respective quantity
2. from 1 Start to output , First output the first non-zero number , Output one bit
3. Judge flag Is it 1, if 1 It means there is 0, Then output all 0, Then output the remaining non-zero numbers from small to large
3、 ... and 、 Code
#include "stdio.h"
int main()
{
int count[10] = {0};
int i = 0 ,j = 0,k = 0;
for(i = 0; i < 10; i++)
{
scanf("%d",&count[i]);
}
int flag = 0;// Used to mark whether there is 0
if(count[0] != 0)
{
flag = 1;// If you have any 0 be flag Position as 1
}
for(i = 1; i < 10; i++)
{
if(count[i] != 0)// from 1 To traverse the , When a non-zero bit is encountered, the output starts
{
for(j = 0; j < count[i]; j++)
{
printf("%d",i);// Output one bit first , Then judge whether there is 0
if(flag == 1)// If there is zero , Then all 0 Output , If there is 2 individual 1,3 individual 0, Then output a 1 Then output all zero outputs and then output the rest 1
{
for(k = 0; k < count[0]; k++)
{
printf("0");
}
flag = 0;
}
// After that, the remaining non-zero bits will be output
}
}
}
return 0;
}边栏推荐
- Opencv display image
- What is the magic of digital collections? Which reliable teams are currently developing
- 关于安装pip3 install chatterbot报错的问题
- How does win11 enable mobile hotspot? How to enable mobile hotspot in win11
- Opportunities and challenges of digital collections from the perspective of technology development team
- ant使用总结(二):相关命令说明
- Operating mongodb in node
- HierarchyViewer工具找不到 HierarchyViewer位置
- 数字藏品火热背后需要强大的技术团队支持 北方技术团队
- 技术开发团队视角看到的数字藏品机遇与挑战
猜你喜欢
![[graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming](/img/04/3121514fcd8fcf1c939cbca7f4c67a.jpg)
[graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming

Software design and Development Notes 2: serial port debugging tool based on QT design

MySQL面试真题(二十五)——常见的分组比较场景

Activity启动模式和生命周期实测结果

数字化工厂建设可划分为三个方面

The performance of nonstandard sprintf code in different platforms

MySQL面试真题(二十一)——金融-贷款逾期

MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选

ant使用总结(三):批量打包apk

runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
随机推荐
PAT 乙等 1021 个位数统计
PAT 乙等 1016 C语言
【斯坦福计网CS144项目】Lab2: TCPReceiver
【数据库备份】通过定时任务完成MySQL数据库的备份
Leetcode topic analysis: factorial training zeroes
Real MySQL interview question (23) -- pinduoduo ball game analysis
How does win11 enable mobile hotspot? How to enable mobile hotspot in win11
MySQL面试真题(二十一)——金融-贷款逾期
阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
ant使用总结(三):批量打包apk
PAT 乙等 1013 C语言
使用链表实现两个多项式相加和相乘
Real MySQL interview question (30) -- shell real estate order analysis
Raspberry pie assert preliminary exercise
The performance of nonstandard sprintf code in different platforms
PAT 乙等 1017 C语言
C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
雷达图canvas
Wireshark TS | 视频 APP 无法播放问题
ssm项目搭建