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

边栏推荐
- The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
- 组件的自定义事件②
- 2022广东省安全员A证第三批(主要负责人)特种作业证考试题库模拟考试平台操作
- Principle and process of embossing
- kubernetes资源对象介绍及常用命令(二)
- Gui Gui programming (XV) - use scale to control font size changes
- ContentType所有类型对比
- How to check ad user information?
- 【mysql学习笔记25】sql语句优化
- [recommendation system] breakthrough and imagination of deep location interactive network dpin for meituan takeout recommendation scenario
猜你喜欢

奥迪AUDI EDI 项目中供应商需要了解哪些信息?

2022年茶艺师(中级)复训题库及答案

凸印的印刷原理及工艺介绍

Wang Yingqi, founder of ones, talks to fortune (Chinese version): is there any excellent software in China?

2022 electrician (intermediate) recurrent training question bank and answers

The triode is a great invention
![[untitled]](/img/c2/63286ba00321c9cdef43ff40635a67.png)
[untitled]

LM08丨网格系列之网格反转(精)

Software testing methods and techniques - overview of basic knowledge

Apple account password auto fill
随机推荐
[untitled]
The database is locked. Is there a solution
长路漫漫、技术作伴
[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
论文学习——水文时间序列相似性查询的分析与研究
2022茶艺师(初级)操作证考试题库及模拟考试
2022 tea master (intermediate) recurrent training question bank and answers
Array: question brushing record
[MySQL learning notes 28] storage function
Eigen matrix operation Library
[programming training 2] sorting subsequence + inverted string
Li Kou daily question - day 31 -1790 Can a string exchange be performed only once to make two strings equal
2022 test questions and mock examinations for main principals of hazardous chemicals business units
Software testing methods and techniques - overview of basic knowledge
How outlook puts together messages with the same discussion
[MySQL learning notes 26] view
如何让两融交易更极速
Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
Apple account password auto fill
Scala language learning-07-constructor