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

边栏推荐
- sqlalchemy创建MySQL_Table
- Scala language learning-07-constructor
- 力扣每日一题-第32天-1822.数组元素积的符号
- 2022年流动式起重机司机考试练习题及在线模拟考试
- 力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
- 【mysql学习笔记25】sql语句优化
- QT -- 1. QT connection database
- Cadence OrCAD capture "network name" is the same, but it is not connected or connected incorrectly. The usage of nodeName of liberation scheme
- 038 network security JS
- [MySQL learning notes 25] SQL statement optimization
猜你喜欢

Custom events of components ①

Gru of RNN
![[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched](/img/8d/cf259b9bb8574aa1842280c9661d1e.jpg)
[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
![[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)](/img/48/de19e8cc007b93a027a906d4d423b2.png)
[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)

base64

Caesar

组件的自定义事件②

Array: question brushing record

2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation

PWN攻防世界int_overflow
随机推荐
Eigen矩阵运算库快速上手
Eigen matrix operation Library
三极管是一项伟大的发明
Why some people earn nearly 10billion a year, while others earn 3000 a month: the details you ignore actually make the most money
Access报表实现小计功能
2022茶艺师(初级)操作证考试题库及模拟考试
base64
TCP/UDP 通信问题整理
2022年茶艺师(中级)复训题库及答案
redisson使用全解——redisson官方文档+注释(上篇)
Custom events of components ①
Teach you how to apply for domestic trademark online step by step
[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
redisson使用全解——redisson官方文档+注释(中篇)
下载Xshell和Xftp
IMDB practice of emotion classification (simplernn, LSTM, Gru)
2022 electrician (intermediate) recurrent training question bank and answers
Caesar
AArdio - 【问题】bass库回调时内存增长的问题
Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years