当前位置:网站首页>[getting started] input n integers and output the smallest K of them
[getting started] input n integers and output the smallest K of them
2022-07-01 07:59:00 【-Heaven rewards diligence-】
describe
Input n It's an integer , Find out the smallest k An integer and output in ascending order
Input description
Enter two integers on the first line n and k
On the second line, enter an array of integers
Output description
From small to large, output the smallest k It's an integer , Separate with spaces .
Example 1
Input :5 2
1 3 5 7 2
Output :1 2
<?php
$num = fgets(STDIN);
$data = fgets(STDIN);
// Total array length and You need to intercept the length of the array
$num_arr = explode(' ',trim($num,"\t\n\r"));
// Intercept the required length
$data_arr = array_slice(explode(' ',trim($data,"\t\n\r")),0,$num_arr[0]);
// Sort From small to large
sort($data_arr);
// Intercept the required array
$res_arr = array_slice($data_arr,0,$num_arr[1]);
echo implode(" ",$res_arr);

边栏推荐
猜你喜欢

She is the "HR of others" | ones character

如何使用layui将数据库中的数据以表格的形式展现出来

【无标题】

LSTM of RNN

QT -- 1. QT connection database

The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?

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

Lm08 mesh series mesh inversion (fine)

Significance and measures of source code encryption

Eigen matrix operation Library
随机推荐
Software testing methods and techniques - overview of basic knowledge
Set up file server Minio for quick use
php laravel微信支付
sqlalchemy创建MySQL_Table
The database is locked. Is there a solution
Huawei modelarts training alexnet model
【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
EDA开源仿真工具verilator入门6:调试实例
How relational databases work
AArdio - 【问题】bass库回调时内存增长的问题
如何使用layui将数据库中的数据以表格的形式展现出来
三极管是一项伟大的发明
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
Lm08 mesh series mesh inversion (fine)
Basic knowledge of MATLAB
Source code analysis of open source API gateway APIs IX
Saving db4i depth camera pictures with MATLAB
【无标题】
Implementation and encapsulation of go universal dynamic retry mechanism
2022 test question bank and simulation test of tea master (primary) operation certificate