题解 | #特殊排序#
特殊排序
https://www.nowcoder.com/practice/57f0f528bff149be9580af66f6292430
#include<cstdio> #include<algorithm> using namespace std; bool comp1(int lhs, int rhs) { if (lhs > rhs) { return true; } else { return false; } } int main() { int n; int max = 0; int arr[1001]; for (int i = 0 ; i < 1001 ; ++i) { arr[i] = ' '; } while (scanf("%d", &n) != EOF) { for (int idx = 0; idx < n; ++idx) { scanf("%d", &arr[idx]); if (arr[idx] > max) { max = arr[idx]; } } if (1 == n) { printf("%d\n%d", max, -1); break; } printf("%d\n", max); sort(arr, arr + n); for (int i = 0; i < n - 1; ++i) { printf("%d ", arr[i]); } } }