题解 | #特殊排序#
特殊排序
https://www.nowcoder.com/practice/57f0f528bff149be9580af66f6292430
#include <iostream> #include <algorithm> using namespace std; int main() { int MaxNumber; int N; cin >> N; if (N <= 0) { return 0; } int arr[N]; int n = 0; for (int i = 0; i < N; ++i) { cin >> arr[i]; } sort(arr, arr + N); MaxNumber = arr[N - 1]; if (N > 0) { cout << MaxNumber << endl; } for (int i = N - 2; i >= 0; --i) { if (arr[i] <= MaxNumber) { n++; } } if (n == 0) { cout << -1; } else { for (int i = 0; i < n; ++i) { cout << arr[i] << " "; } } }