当前位置:网站首页>[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);

边栏推荐
- AArdio - 【问题】bass库回调时内存增长的问题
- Software testing methods and techniques - overview of basic knowledge
- 【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
- She is the "HR of others" | ones character
- Two expressions of string
- Five combination boxing, solving six difficult problems on campus and escorting the construction of educational informatization
- 2022 test questions and mock examinations for main principals of hazardous chemicals business units
- 【R语言】两个/N个数据合并merge函数
- getInputStream() has already been called for this request
- Significance and measures of source code encryption
猜你喜欢

Gui Gui programming (XV) - use scale to control font size changes

2022危险化学品经营单位主要负责人试题及模拟考试

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

Software testing methods and techniques - overview of basic knowledge

【入门】取近似值

LSTM of RNN

Access报表实现小计功能

Significance and measures of source code encryption

base64

PostgreSQL source code learning (26) -- windows vscode remote debugging PostgreSQL on Linux
随机推荐
Rk3399 platform development series explanation (network debugging) 7.30. What will affect the sending process of TCP packets?
长路漫漫、技术作伴
【mysql学习笔记27】存储过程
[software] phantomjs screenshot
Eigen矩阵运算库快速上手
Why some people earn nearly 10billion a year, while others earn 3000 a month: the details you ignore actually make the most money
SQL number injection and character injection
How do the top ten securities firms open accounts? In addition, is it safe to open a mobile account?
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
Set up file server Minio for quick use
Insufficient executors to build thread pool
base64
Vhost kick & call principle
IMDB practice of emotion classification (simplernn, LSTM, Gru)
Sorting out tcp/udp communication problems
2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform
Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
Latex formula code
I bet on performance and won the CTO of the company. I want to build Devops platform!