当前位置:网站首页>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;
}边栏推荐
- jvm-01. Instruction rearrangement
- Dolphin scheduler dolphin scheduling upgrade code transformation -upgradedolphin scheduler
- PAT 乙等 1021 个位数统计
- Heimdall database proxy scale out 20 times
- Leetcode topic analysis: factorial training zeroes
- 雷达图canvas
- Pat class B 1010 C language
- 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
- Use of visdom
- Android handler memory leak kotlin memory leak handling
猜你喜欢

Prometheus, incluxdb2.2 installation and flume_ Export download compile use

HierarchyViewer工具找不到 HierarchyViewer位置

How can digital collections empower economic entities?

The performance of nonstandard sprintf code in different platforms

A bit of knowledge - folding forging and Damascus steel

Dolphin scheduler dolphin scheduling upgrade code transformation -upgradedolphin scheduler

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

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

Use of visdom

Android handler memory leak kotlin memory leak handling
随机推荐
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机
数字化工厂建设可划分为三个方面
PAT 乙等 1020.月饼
ORB_SLAM2运行
Prometheus, incluxdb2.2 installation and flume_ Export download compile use
jvm-03.jvm内存模型
Android handler memory leak kotlin memory leak handling
Basic calculator for leetcode topic analysis
jvm-01.指令重排
【开源项目】excel导出lua配置表工具
Use of visdom
AHA C language Chapter 8 game time is up (lesson 29)
[graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
MySQL面试真题(二十三)——拼多多-球赛分析
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
MySQL character set
Redis cache penetration solution - bloom filter
Basic calculator II for leetcode topic analysis
Wechat applet: unfashionable love talk
About the error of installing PIP3 install chatterbot