当前位置:网站首页>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;
}边栏推荐
- 【开源项目】excel导出lua配置表工具
- Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
- 【数据库备份】通过定时任务完成MySQL数据库的备份
- 制造业数字化转型存在问题及原因分析
- 如何指定pig-register项目日志的输出路径
- The difference between SaaS software and traditional software delivery mode
- True MySQL interview question (21) - Finance - overdue loan
- Explicability of counter attack based on optimal transmission theory
- App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value
- Raspberry pie assert preliminary exercise
猜你喜欢

HierarchyViewer工具找不到 HierarchyViewer位置

C primer plus learning notes - 2. Constant and formatted IO (input / output)

Opportunities and challenges of digital collections from the perspective of technology development team

Wireshark TS | video app cannot play

Use of visdom

Addressing and addressing units

Redis cache penetration solution - bloom filter

【斯坦福计网CS144项目】Lab2: TCPReceiver

数字藏品赋能实体产业释放了哪些利好?

技术开发团队视角看到的数字藏品机遇与挑战
随机推荐
jvm-04.对象的内存布局
PAT 乙等 1020.月饼
C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
Real MySQL interview question (23) -- pinduoduo ball game analysis
android Handler内存泄露 kotlin内存泄露处理
阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
Centos7部署radius服务-freeradius-3.0.13-15.el7集成mysql
数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发
MySQL character set
Pat class B 1011 C language
How can digital collections empower economic entities?
Adnroid activity screenshot save display to album view display picture animation disappear
June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
编址和编址单位
jvm-06.垃圾回收器
True MySQL interview question (21) - Finance - overdue loan
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
AHA C language Chapter 7 you can do more with it (talks 27-28)
Explicability of counter attack based on optimal transmission theory