POJ 2388 && HDU 1157 Who's in the Middle(水~)
2015-08-27 09:42
549 查看
Description
给定n(n为奇数)个数,输出其中位数
Input
第一行为n,之后n行每行一个数(1<=n<=10000)
Output
输出这n个数的中位数
Sample Input
5
2
4
1
3
5
Sample Output
3
Solution
纯净水…
Code
给定n(n为奇数)个数,输出其中位数
Input
第一行为n,之后n行每行一个数(1<=n<=10000)
Output
输出这n个数的中位数
Sample Input
5
2
4
1
3
5
Sample Output
3
Solution
纯净水…
Code
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define maxn 10001 int num[maxn]; int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) scanf("%d",&num[i]); sort(num,num+n); printf("%d\n",num[n/2]); } return 0; }
相关文章推荐
- HDU4324 - Triangle LOVE 拓补排序
- 天声人語 20150827
- 流式布局之等比列缩放的盒子。
- 关于android中Calendar的赋值
- 解决android SDK更新报错
- 教你如何做dns反向解析
- POJ 2386 Lake Counting(dfs)
- HoughCircles 函数
- jQuery入门:CSS,样式和大小
- IOS 屏幕尺寸、分辨率、点之间的相互关系
- ztree一次性加载数据
- 使用cocos compile -p android时总是报错误 BUILD FAILED \ant\build.xml:892
- 连15随笔
- 2015.6.5
- C++ Builder XE8 安卓开发之菜单键的触发代码
- Linux第四天
- web点滴
- textarea和mysql中的换行符问题
- 利用layer.js和jQuery在form提交页面添加loading层
- POJ 2376 Cleaning Shifts(贪心)