题解 | 中位数

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	vector<int>ans;
	while(cin>>n) {
	    if(n==0)break;
	    ans.clear();
	    while(n--){
	        int x;cin>>x;
	        ans.push_back(x);
	    }
		sort(ans.begin(),ans.end());
		int k=ans.size();
		if(k%2==0) {
			cout<<(ans[k/2]+ans[k/2-1])/2<<endl;
		} else cout<<ans[k/2]<<endl;
	}

}

直接写一个sort完事

全部评论

相关推荐

05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务