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

边栏推荐
- What information does the supplier need to know about Audi EDI project?
- AUTOSAR learning record (1) – ECUM_ Init
- Principle and process of embossing
- 2022危险化学品经营单位主要负责人试题及模拟考试
- Microsoft stream - how to modify video subtitles
- 三极管是一项伟大的发明
- H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?
- 2022电工(中级)复训题库及答案
- Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)
- Scala语言学习-07-构造器
猜你喜欢
随机推荐
AUTOSAR learning record (1) – ECUM_ Init
Latex formula code
Redisson uses the full solution - redisson official document + comments (Part 2)
【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion
她就是那个「别人家的HR」|ONES 人物
[R language] two /n data merge functions
sqlalchemy创建MySQL_Table
Office365 - how to use stream app to watch offline files at any time
2022制冷与空调设备运行操作国家题库模拟考试平台操作
Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
组件的自定义事件②
Browser local storage
Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证
Apple account password auto fill
Li Kou daily question - day 31 -1790 Can a string exchange be performed only once to make two strings equal
Redisson uses the complete solution - redisson official documents + Notes (Part 1)
[batch DOS CMD summary] extension variables - delay variables CMD /v:on, CMD /v:off, SETLOCAL enabledelayedexpansion, disabledelayedexpansion
[programming training 2] sorting subsequence + inverted string
matlab保存DB4i深度相机图片









