#输入整型数组和排序标识,对其元素按照升序或降序进行排序#
输入整型数组和排序标识,对其元素按照升序或降序进行排序
https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for(int i=0; i<n; i++){ cin >> a[i]; } sort(a.begin(), a.end()); int tag; cin >> tag; if(tag == 0){ for(auto i:a) cout << i <<" "; } if(tag == 1){ reverse(a.begin(),a.end()); for(auto i:a) cout << i <<" "; } return 0; }