0
点赞
收藏
分享

微信扫一扫

hdu 1157 Who's in the Middle (水题,中位数)

慎壹 2023-07-18 阅读 55


小记:GNU C++硬是要我把变量都定义到main()函数外才能让我AC...


思路:读入数据存入数组,排序,输出中间那个,输入保证是奇数个。从0开始存,答案就是排好序后的第n/2个


代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-8

const int MAX_ = 10010;

int p[MAX_], n;

int main(){
	while(~scanf("%d",&n)){
        for(int i = 0; i < n; ++i){
            scanf("%d",&p[i]);
        }
        sort(p,p+n);
        printf("%d\n",p[n/2]);
	}
	return 0;
}




举报

相关推荐

0 条评论