当前位置:网站首页>【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
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;
}

边栏推荐
- [MySQL learning notes 28] storage function
- QT -- 1. QT connection database
- Download xshell and xftp
- Principle and process of embossing
- AUTOSAR learning record (1) – ECUM_ Init
- TodoList经典案例①
- [programming compulsory training 3] find the longest consecutive number string in the string + the number that appears more than half of the times in the array
- 十大劵商如何开户?另外,手机开户安全么?
- Apple account password auto fill
- Sorting out tcp/udp communication problems
猜你喜欢

The database is locked. Is there a solution

Aardio - 阴影渐变文字

Custom events of components ①

redisson使用全解——redisson官方文档+注释(中篇)

PWN攻防世界int_overflow

postgresql源码学习(26)—— Windows vscode远程调试Linux上的postgresql

【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion

Atguigu---- scaffold --02- use scaffold (2)

SQL number injection and character injection
![[programming training 2] sorting subsequence + inverted string](/img/96/87750c5d3954ef6c39cce073e8b9ae.png)
[programming training 2] sorting subsequence + inverted string
随机推荐
【mysql学习笔记26】视图
[R language] two /n data merge functions
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
关系数据库如何工作
matlab保存DB4i深度相机图片
漏刻有时API接口实战开发系列(14):身份证实名鉴权验证
Download xshell and xftp
Redisson uses the full solution - redisson official document + comments (Part 2)
redisson使用全解——redisson官方文档+注释(下篇)
软件测试方法和技术 - 基础知识概括
PWN攻防世界int_overflow
力扣每日一题-第31天-1502.判断能否形成等差数列
Kickback -- find the first palindrome character in a group of characters
Apple account password auto fill
【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion
2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform
IMDB practice of emotion classification (simplernn, LSTM, Gru)
How to use layui to display the data in the database in the form of tables
2022茶艺师(初级)操作证考试题库及模拟考试