C++,STL的正确使用方法
输入整型数组和排序标识,对其元素按照升序或降序进行排序
http://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin >> n){
vector<int> v;
int m;
for(int i=0; i<n; i++){
cin >> m;
v.push_back(m);
}
int k;
cin >> k;
if(k==0){
sort(v.begin(),v.end());
}
else if(k==1){
sort(v.begin(),v.end(),greater<int>());
}
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
cout << endl;
}
}