当前位置:网站首页>[getting started] input n integers and output the smallest K of them
[getting started] input n integers and output the smallest K of them
2022-07-01 07:59:00 【-Heaven rewards diligence-】
describe
Input n It's an integer , Find out the smallest k An integer and output in ascending order
Input description
Enter two integers on the first line n and k
On the second line, enter an array of integers
Output description
From small to large, output the smallest k It's an integer , Separate with spaces .
Example 1
Input :5 2
1 3 5 7 2
Output :1 2
<?php
$num = fgets(STDIN);
$data = fgets(STDIN);
// Total array length and You need to intercept the length of the array
$num_arr = explode(' ',trim($num,"\t\n\r"));
// Intercept the required length
$data_arr = array_slice(explode(' ',trim($data,"\t\n\r")),0,$num_arr[0]);
// Sort From small to large
sort($data_arr);
// Intercept the required array
$res_arr = array_slice($data_arr,0,$num_arr[1]);
echo implode(" ",$res_arr);

边栏推荐
- 三极管是一项伟大的发明
- php laravel微信支付
- Caesar
- [kv260] generate chip temperature curve with xadc
- 力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
- STM32 uses esp01s to go to the cloud, mqtt FX debugging
- Cyclic neural network
- How to use layui to display the data in the database in the form of tables
- ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
- [MySQL learning notes 28] storage function
猜你喜欢
随机推荐
【力扣10天SQL入门】Day10 控制流
[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)
The database is locked. Is there a solution
2022年茶艺师(中级)复训题库及答案
2022 mobile crane driver test exercises and online simulation test
PWN攻防世界int_overflow
Download xshell and xftp
她就是那个「别人家的HR」|ONES 人物
How do the top ten securities firms open accounts? In addition, is it safe to open a mobile account?
Insufficient executors to build thread pool
ContentType所有类型对比
What information does the supplier need to know about Audi EDI project?
【mysql学习笔记28】存储函数
base64
【入门】取近似值
How to get a SharePoint online site created using the office365 group template
Basic number theory -- combinatorial number
[MySQL learning notes 26] view
Redisson uses the full solution - redisson official documents + comments (Part 2)
LSTM of RNN









