当前位置:网站首页>【入门】输入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);

边栏推荐
- Android screen adaptation (using constraintlayout), kotlin array sorting
- The database is locked. Is there a solution
- 十大劵商如何开户?另外,手机开户安全么?
- 【mysql学习笔记27】存储过程
- 下载Xshell和Xftp
- 【mysql学习笔记28】存储函数
- redisson使用全解——redisson官方文档+注释(下篇)
- 力扣每日一题-第31天-1502.判断能否形成等差数列
- 【无标题】
- Cadence OrCAD capture "network name" is the same, but it is not connected or connected incorrectly. The usage of nodeName of liberation scheme
猜你喜欢

Access报表实现小计功能

Android screen adaptation (using constraintlayout), kotlin array sorting

2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation

Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years

Basic knowledge of MATLAB

源代码加密的意义和措施

Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure

Array: question brushing record

The database is locked. Is there a solution

Teach you how to apply for domestic trademark online step by step
随机推荐
redisson使用全解——redisson官方文档+注释(中篇)
Access报表实现小计功能
Huawei modelarts training alexnet model
SQL number injection and character injection
Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
2022年流动式起重机司机考试练习题及在线模拟考试
2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform
2022年茶艺师(中级)复训题库及答案
Todolist classic case ①
Wang Yingqi, founder of ones, talks to fortune (Chinese version): is there any excellent software in China?
【无标题】
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
Array: question brushing record
Caesar
【mysql学习笔记26】视图
浏览器本地存储
Rk3399 platform development series explanation (network debugging) 7.30. What will affect the sending process of TCP packets?
2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作
How to check ad user information?
SharePoint - how to quickly check whether SharePoint is standard or enterprise edition?