当前位置:网站首页>[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order
2022-07-01 07:59:00 【-Heaven rewards diligence-】
describe
Enter an integer array and sort ID , Sort its elements in ascending or descending order
Input description
Enter the number of array elements in the first line
In the second line, enter the array to be sorted , Each number is separated by a space
Enter an integer in the third line 0 or 1.0 For ascending sort ,1 Represents a descending sort
Output description
Output ordered numbers
Example 1
Input :8
1 2 4 9 3 55 64 25
0
Output :1 2 3 4 9 25 55 64
Example 2
Input :8
1 2 4 9 3 55 64 25
0
Output :1 2 3 4 9 25 55 64
<?php
$num = intval(fgets(STDIN));
$arr = fgets(STDIN);
$flag = intval(fgets(STDIN));
$arr = explode(' ',trim($arr,"\t\n\r"));
$arr = array_slice($arr,0,$num);
if ($flag){
rsort($arr);
$arr = implode(' ',$arr);
$arr = trim($arr," \t\n\r");
echo $arr;
}else{
sort($arr);
$arr = implode(' ',$arr);
$arr = trim($arr," \t\n\r");
echo $arr;
}
边栏推荐
- ContentType所有类型对比
- Cyclic neural network
- [kv260] generate chip temperature curve with xadc
- Deep learning systematic learning
- Li Kou daily question - day 31 -202 Happy number
- MATLAB之基础知识
- Instead of houses, another kind of capital in China is rising
- TCP/UDP 通信问题整理
- 【mysql学习笔记26】视图
- 2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform
猜你喜欢
web254
Gru of RNN
LSTM of RNN
Set up file server Minio for quick use
2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform
凸印的印刷原理及工艺介绍
[kv260] generate chip temperature curve with xadc
软件测试方法和技术 - 基础知识概括
The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
Conscience Amway universal wheel SolidWorks model material website
随机推荐
038 network security JS
[kv260] generate chip temperature curve with xadc
How to check ad user information?
2022 electrician (intermediate) recurrent training question bank and answers
QT -- 1. QT connection database
Principle and process of embossing
PWN攻防世界int_overflow
window c盘满了
Differential: definition of total differential, partial derivative, gradient
【技能】创建.bat快速打开网页
I bet on performance and won the CTO of the company. I want to build Devops platform!
EDA开源仿真工具verilator入门6:调试实例
良心安利万向轮 SolidWorks模型素材网站
Chinese font Gan: zi2zi
H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?
How to use layui to display the data in the database in the form of tables
kubernetes资源对象介绍及常用命令(二)
【力扣10天SQL入门】Day9 控制流
长路漫漫、技术作伴
The database is locked. Is there a solution