题解 | #中位数#
中位数
https://www.nowcoder.com/practice/2364ff2463984f09904170cf6f67f69a
#include<iostream> #include<algorithm> using namespace std; const int N = 1e5 + 10; int arr[N]; int main(void) { int n; //代表n轮 while (cin >> n) { if (n == 0) break; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); if (n % 2 == 0) cout << (arr[n / 2] + arr[(n - 1) / 2]) / 2 << endl; else cout << arr[(n - 1) / 2] << endl; } return 0; }