当前位置:网站首页>【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
2022-07-01 07:55:00 【-天道酬勤-】
描述
输入整型数组和排序标识,对其元素按照升序或降序进行排序
输入描述
第一行输入数组元素个数
第二行输入待排序的数组,每个数用空格隔开
第三行输入一个整数0或1。0代表升序排序,1代表降序排序
输出描述
输出排好序的数字
示例1
输入:8
1 2 4 9 3 55 64 25
0
输出:1 2 3 4 9 25 55 64
示例2
输入:8
1 2 4 9 3 55 64 25
0
输出: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;
}

边栏推荐
- 关系数据库如何工作
- [untitled]
- 2022年流动式起重机司机考试练习题及在线模拟考试
- How to troubleshoot SharePoint online map network drive failure?
- Vhost kick & call principle
- Teach you how to apply for domestic trademark online step by step
- 2022 tea master (intermediate) recurrent training question bank and answers
- Latex table
- Redisson uses the complete solution - redisson official documents + Notes (Part 1)
- How outlook puts together messages with the same discussion
猜你喜欢

Introduction to kubernetes resource objects and common commands (II)

How outlook puts together messages with the same discussion

SQL number injection and character injection
![[programming training 2] sorting subsequence + inverted string](/img/96/87750c5d3954ef6c39cce073e8b9ae.png)
[programming training 2] sorting subsequence + inverted string

Eigen matrix operation Library

kubernetes资源对象介绍及常用命令(二)

她就是那个「别人家的HR」|ONES 人物
![[kv260] generate chip temperature curve with xadc](/img/fc/e5e4648b09b1123b2d494b75a9f8f7.png)
[kv260] generate chip temperature curve with xadc

Basic knowledge of MATLAB

【mysql学习笔记25】sql语句优化
随机推荐
The triode is a great invention
TodoList经典案例①
力扣——求一组字符中的第一个回文字符
漏刻有时API接口实战开发系列(14):身份证实名鉴权验证
Software testing methods and techniques - overview of basic knowledge
sqlalchemy创建MySQL_Table
良心安利万向轮 SolidWorks模型素材网站
matlab保存DB4i深度相机图片
The database is locked. Is there a solution
AUTOSAR learning record (1) – ECUM_ Init
SharePoint - modify web application authentication using PowerShell
Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
Array: question brushing record
Source code analysis of open source API gateway APIs IX
redisson看门狗机制,redisson看门狗性能问题,redisson源码解析
Custom events of components ②
Caesar
Cyclic neural network
ContentType所有类型对比