题解 | #中位数#
中位数
https://www.nowcoder.com/practice/2364ff2463984f09904170cf6f67f69a
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while(cin>>n){
if(n==0)return 0;
vector<int>v;
while(n--){
int temp;cin>>temp;
v.push_back(temp);
}
sort(v.begin(),v.end());
if(v.size()%2==1)//奇数
cout<<v[v.size()/2]<<endl;
else
cout<<(v[v.size()/2]+v[v.size()/2-1])/2<<endl;
}
}
// 64 位输出请用 printf("%lld")

查看21道真题和解析