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

边栏推荐
- sqlalchemy创建MySQL_Table
- Microsoft stream - how to modify video subtitles
- 【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
- Missing API interface actual development series (14): ID card real name authentication verification
- php laravel微信支付
- Oracle create auto increment ID
- [software] phantomjs screenshot
- 2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
- 漏刻有时API接口实战开发系列(14):身份证实名鉴权验证
- 【R语言】两个/N个数据合并merge函数
猜你喜欢

【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion
![[kv260] generate chip temperature curve with xadc](/img/fc/e5e4648b09b1123b2d494b75a9f8f7.png)
[kv260] generate chip temperature curve with xadc

How to troubleshoot SharePoint online map network drive failure?

web254

【网站架构】一招搞定90%的分布式事务,实打实介绍数据库事务、分布式事务的工作原理应用场景

Cyclic neural network

The database is locked. Is there a solution

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

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

2022 test questions and mock examinations for main principals of hazardous chemicals business units
随机推荐
[website architecture] solve 90% of distributed transactions in one move, and introduce the working principles and application scenarios of database transactions and distributed transactions
go通用动态重试机制解决方案的实现与封装
【mysql学习笔记28】存储函数
[R language] two /n data merge functions
2022 mobile crane driver test exercises and online simulation test
matlab保存DB4i深度相机图片
2022年流动式起重机司机考试练习题及在线模拟考试
她就是那个「别人家的HR」|ONES 人物
Oracle创建自增id
How outlook puts together messages with the same discussion
Introduction to kubernetes resource objects and common commands (II)
PWN攻防世界int_overflow
力扣每日一题-第31天-1502.判断能否形成等差数列
SQL number injection and character injection
How to make the two financial transactions faster
Basic number theory -- combinatorial number
kubernetes资源对象介绍及常用命令(二)
2022年茶艺师(中级)复训题库及答案
【无标题】
[programming training 2] sorting subsequence + inverted string