当前位置:网站首页>【入门】输入n个整数,输出其中最小的k个
【入门】输入n个整数,输出其中最小的k个
2022-07-01 07:55:00 【-天道酬勤-】
描述
输入n个整数,找出其中最小的k个整数并按升序输出
输入描述
第一行输入两个整数n和k
第二行输入一个整数数组
输出描述
从小到大输出最小的k个整数,用空格分开。
示例1
输入:5 2
1 3 5 7 2
输出:1 2
<?php
$num = fgets(STDIN);
$data = fgets(STDIN);
// 数组总长度 和 需要截取数组的长度
$num_arr = explode(' ',trim($num,"\t\n\r"));
// 截取需要的长度
$data_arr = array_slice(explode(' ',trim($data,"\t\n\r")),0,$num_arr[0]);
// 排序 由小到大
sort($data_arr);
// 截取需要的数组
$res_arr = array_slice($data_arr,0,$num_arr[1]);
echo implode(" ",$res_arr);

边栏推荐
- Thesis learning -- Analysis and Research on similarity query of hydrological time series
- Principle and process of embossing
- base64
- Atguigu---- scaffold --02- use scaffold (2)
- [R language] two /n data merge functions
- Long way to go with technology
- [programming training] delete public characters (hash mapping) + team competition (greedy)
- Caesar
- Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
- AArdio - 【问题】bass库回调时内存增长的问题
猜你喜欢

浅谈CVPR2022的几个研究热点

I bet on performance and won the CTO of the company. I want to build Devops platform!

Custom events of components ①
![[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched](/img/8d/cf259b9bb8574aa1842280c9661d1e.jpg)
[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched

She is the "HR of others" | ones character

Download xshell and xftp

2022制冷与空调设备运行操作国家题库模拟考试平台操作
![[programming compulsory training 3] find the longest consecutive number string in the string + the number that appears more than half of the times in the array](/img/5e/068268857b8c7c2065ba552fd23dbb.png)
[programming compulsory training 3] find the longest consecutive number string in the string + the number that appears more than half of the times in the array

Android screen adaptation (using constraintlayout), kotlin array sorting

Cyclic neural network
随机推荐
Huawei modelarts training alexnet model
Source code analysis of open source API gateway APIs IX
Scala language learning-07-constructor
Latex formula code
三极管是一项伟大的发明
TodoList经典案例①
STM32 uses esp01s to go to the cloud, mqtt FX debugging
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
长路漫漫、技术作伴
[untitled]
Redisson uses the full solution - redisson official documents + comments (Part 2)
[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)
[kv260] generate chip temperature curve with xadc
ContentType所有类型对比
Basic number theory -- combinatorial number
[recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario
【技能】创建.bat快速打开网页
postgresql源码学习(26)—— Windows vscode远程调试Linux上的postgresql
IMDB practice of emotion classification (simplernn, LSTM, Gru)
Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)