裸地中位数
sort1Y
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>L;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int i,x;
L.clear();
for(i=0;i<n;i++){
scanf("%d",&x);
L.push_back(x);
}
sort(L.begin(),L.end());
printf("%d\n",L[(n-1)/2]);
}
return 0;
}
本文介绍了一种通过排序查找数组中位数的简单算法。该算法使用标准C++库中的vector容器存储输入数据,并利用sort函数对数据进行排序,最后输出位于数组中间位置的元素作为中位数。
332

被折叠的 条评论
为什么被折叠?



