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

边栏推荐
- Wang Yingqi, founder of ones, talks to fortune (Chinese version): is there any excellent software in China?
- Conscience Amway universal wheel SolidWorks model material website
- [kv260] generate chip temperature curve with xadc
- 如何使用layui将数据库中的数据以表格的形式展现出来
- [software] phantomjs screenshot
- Scala language learning-07-constructor
- getInputStream() has already been called for this request
- Atguigu---- scaffold --02- use scaffold (2)
- Significance and measures of source code encryption
- 如何让两融交易更极速
猜你喜欢

window c盘满了

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

H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?

关系数据库如何工作

Principle and process of embossing

LSTM of RNN

Microsoft stream - how to modify video subtitles

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

PWN攻防世界int_overflow

Basic knowledge of MATLAB
随机推荐
2022 tea master (intermediate) recurrent training question bank and answers
getInputStream() has already been called for this request
2022年茶艺师(中级)复训题库及答案
SharePoint - modify web application authentication using PowerShell
Principle and process of embossing
SharePoint - how to quickly check whether SharePoint is standard or enterprise edition?
Insufficient executors to build thread pool
【mysql学习笔记27】存储过程
Sqlalchemy creating MySQL_ Table
Kickback -- find the first palindrome character in a group of characters
H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?
Set up file server Minio for quick use
ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
web254
力扣每日一题-第31天-1502.判断能否形成等差数列
The Windows C disk is full
Caesar
Eigen矩阵运算库快速上手
She is the "HR of others" | ones character
SQL number injection and character injection