题解 | #HW字符串操作5 按要求排序#
输入整型数组和排序标识,对其元素按照升序或降序进行排序
https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
/*
HW字符串操作5 按要求排序
太简单了,直接秒
*/
#include <algorithm>
#include <iostream>
using namespace std;
int a[1010];
int n;
bool cmp0(int x,int y){return x<y;}
bool cmp1(int x,int y){return x>y;}
int main() {
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
int flag;
cin>>flag;
if(flag)stable_sort(a, a+n,cmp1);
else stable_sort(a,a+n,cmp0);
for(int i=0;i<n;i++)cout<<a[i]<<" ";
return 0;
}
// 64 位输出请用 printf("%lld")