题解 | #特殊排序#
特殊排序
https://www.nowcoder.com/practice/57f0f528bff149be9580af66f6292430
#include<vector> #include<string> #include<iostream> #include<tuple> #include<algorithm> using namespace std; int main() { int N; vector<int> vec; cin >> N; while (N--) { int x; cin >> x; vec.push_back(x); } auto max_x = max_element(vec.begin(), vec.end()); cout << *max_x << endl; vec.erase(max_x); sort(vec.begin(), vec.end()); if (vec.empty()) { cout << -1; }else{ for (auto it = vec.begin(); it != vec.end(); it++) { cout << *it << " "; } } }
关键是学会用:
- max_element
- vec.erase