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

边栏推荐
- Eigen matrix operation Library
- How to make the two financial transactions faster
- 力扣每日一题-第32天-1822.数组元素积的符号
- She is the "HR of others" | ones character
- Latex formula code
- The triode is a great invention
- [MySQL learning notes 25] SQL statement optimization
- 力扣——求一组字符中的第一个回文字符
- [MySQL learning notes 26] view
- I bet on performance and won the CTO of the company. I want to build Devops platform!
猜你喜欢

MATLAB之基础知识

2022年流动式起重机司机考试练习题及在线模拟考试

Microsoft stream - how to modify video subtitles

SQL number injection and character injection

Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)

Minecraft 1.16.5 module development (51) tile entity

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

The triode is a great invention

2022 test questions and mock examinations for main principals of hazardous chemicals business units

【mysql学习笔记25】sql语句优化
随机推荐
Kickback -- find the first palindrome character in a group of characters
How to use layui to display the data in the database in the form of tables
PWN攻防世界int_overflow
Apple account password auto fill
The database is locked. Is there a solution
论文学习——水文时间序列相似性查询的分析与研究
SQL number injection and character injection
redisson使用全解——redisson官方文档+注释(下篇)
2022 test question bank and simulation test of tea master (primary) operation certificate
Two expressions of string
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)
Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)
2022危险化学品经营单位主要负责人试题及模拟考试
How to troubleshoot SharePoint online map network drive failure?
[R language] two /n data merge functions
[skill] create Bat quick open web page
Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
Custom events of components ①
What information does the supplier need to know about Audi EDI project?