当前位置:网站首页>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;
}边栏推荐
- Wechat applet; AI intelligent dubbing assistant
- C primer plus學習筆記 —— 2、常量與格式化IO(輸入/輸出)
- Alibaba cloud object storage oss+picgo+typera implements the construction map
- 使用链表实现两个多项式相加和相乘
- PAT 乙等 1023 组个最小数
- Opencv display image
- Wechat applet: elderly blessing short video
- MySQL面试真题(二十四)——行列互换
- Android handler memory leak kotlin memory leak handling
- 阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
猜你喜欢

True MySQL interview question (24) -- row column exchange

Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration

jvm-06.垃圾回收器

C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)

Activity startup mode and life cycle measurement results

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

制造业数字化转型存在问题及原因分析

ant使用总结(二):相关命令说明

jvm-01. Instruction rearrangement

Wireshark TS | 视频 APP 无法播放问题
随机推荐
True MySQL interview question (21) - Finance - overdue loan
jvm-06. Garbage collector
最优传输理论下对抗攻击可解释性
node中操作mongoDB
Analysis on the problems and causes of digital transformation of manufacturing industry
Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机
How can digital collections empower economic entities?
The difference between SaaS software and traditional software delivery mode
Real MySQL interview questions (25) -- common group comparison scenarios
Leetcode topic analysis: factorial training zeroes
编址和编址单位
华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
Centos7 deploy radius service -freeradius-3.0.13-15 EL7 integrating MySQL
PAT 乙等 1024 科学记数法 C语言
Behind the hot digital collections, a strong technical team is needed to support the northern technical team
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions
PAT 乙等 1023 组个最小数
App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value