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

边栏推荐
- Li Kou daily question - day 31 -1502 Judge whether an arithmetic sequence can be formed
- Aardio - 阴影渐变文字
- 038 network security JS
- The triode is a great invention
- 2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作
- [software] phantomjs screenshot
- The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
- 浅谈CVPR2022的几个研究热点
- How to check ad user information?
- 【R语言】年龄性别频数匹配 挑选样本 病例对照研究,对年龄性别进行频数匹配
猜你喜欢

2022 test question bank and simulation test of tea master (primary) operation certificate

【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion

Wang Yingqi, founder of ones, talks to fortune (Chinese version): is there any excellent software in China?

她就是那个「别人家的HR」|ONES 人物

window c盘满了

IMDB practice of emotion classification (simplernn, LSTM, Gru)

SQL number injection and character injection

2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform

Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?

web254
随机推荐
三极管是一项伟大的发明
Android screen adaptation (using constraintlayout), kotlin array sorting
力扣——求一组字符中的第一个回文字符
Principle and process of embossing
AUTOSAR learning record (1) – ECUM_ Init
Latex formula code
Kickback -- find the first palindrome character in a group of characters
Li Kou daily question - day 31 -202 Happy number
Gru of RNN
Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)
038 network security JS
[MySQL learning notes 25] SQL statement optimization
2022茶艺师(初级)操作证考试题库及模拟考试
2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作
Todolist classic case ①
How to use layui to display the data in the database in the form of tables
[skill] create Bat quick open web page
MATLAB之基础知识
Aardio - 自己构造的getIconHandle的方法
Significance and measures of source code encryption