poj2388 who is in the middle

xiaoxiao2021-02-28  46

//题意:给定一组数,求中位数

//思路:直接快排

#include <iostream> #include <algorithm> using namespace std; bool cmp(const int a, const int b) { return a < b; } int main() { ios :: sync_with_stdio(false); cin.tie(0); int t; while(cin >> t){ int *n = new int [t]; for(int i = 0; i < t; i++) cin >> n[i]; sort(n, n+t, cmp); if(t & 1){ cout << n[t/2] << endl; }else cout << n[t/2-1] << endl; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2632327.html

最新回复(0)