题解 | #特殊排序#
特殊排序
https://www.nowcoder.com/practice/57f0f528bff149be9580af66f6292430
#include <iostream> using namespace std; const int N = 1001; int q[N]; void quick_sort(int q[], int l, int r){ if(l >= r) return ; int i = l - 1, j = r + 1, mid = q[l + r >> 1]; while (i < j) { do i ++; while(q[i] < mid); do j --; while(q[j] > mid); if(i < j) swap(q[i], q[j]); } quick_sort(q, l, j); quick_sort(q, j + 1, r); } int main() { int n; while (cin >> n) { for(int i = 0; i < n; i ++){ cin >> q[i]; } quick_sort(q, 0, n - 1); cout << q[n - 1] << endl; if(n > 1){ for(int i = 0; i < n - 1; i ++) cout << q[i] << " "; }else{ cout << - 1; } cout << endl; } return 0; } // 64 位输出请用 printf("%lld")