课程练习一-Problem Q

Problem Description
FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. 

Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.
 

Input
* Line 1: A single integer N <br> <br>* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
 

Output
* Line 1: A single integer that is the median milk output.
 

Sample Input
5 2 4 1 3 5
 

Sample Output
3
 
题意: 就是求一串数中中间大小的数

思路:将数存到数组中,排下序,取数组下标中间的数就是了。

代码:
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int N;
cin>>N;
int a[10001];
memset(a,0,sizeof(a));
for(int i=0;i<N;i++)
{
cin>>a[i];
}
sort(a,a+N);
int m=(N)/2;
cout<<a[m]<<endl;
system("pause");
return 0;

### JavaScript 练习题网站推荐 以下是几个适合学习和练习 JavaScript 的优质资源站点: #### 1. **Codecademy** Codecademy 提供结构化的课程,帮助初学者快速掌握 JavaScript 基础语法及其实际应用。该平台通过交互式编程环境让用户能够实时编写代码并查看运行效果[^1]。 #### 2. **LeetCode** LeetCode 是个专注于算法与数据结构训练的在线平台,其中也包含了大量基于 JavaScript 实现的题目。这些题目涵盖了从简单到复杂的各种场景,非常适合希望提升逻辑思维能力的学习者[^4]。 #### 3. **FreeCodeCamp** FreeCodeCamp 不仅提供免费的教程文章,还设计了许多项目导向型的任务来巩固所学知识。它特别强调实践操作的重要性,在完成系列挑战之后可以获得认证证书作为成就证明[^3]。 #### 4. **HackerRank** 类似于 LeetCode , HackerRank 同样提供了丰富的技术面试准备材料以及竞赛活动机会 。 用户可以按照难度等级挑选合适的 JavaScript 编程测试来进行自我检测 和 技能提高 [^2]. #### 5. **Codewars** Codewars 使用武士升级的概念激励玩家不断解决新的编码难题。这里的社区氛围活跃,允许用户提交自己的解决方案并与他人分享经验心得。每道 katas 都经过精心策划以促进特定技能的发展 [^1]. ```javascript // 示例:简单的 JavaScript 函数实现斐波那契数列 function fibonacci(n) { let fib = []; for(let i=0;i<n;i++){ if(i<2){ fib.push(1); } else{ fib.push(fib[i-1]+fib[i-2]); } } return fib; } console.log(fibonacci(10)); // 输出前十个斐波那契数值 ``` 上述列举了些主流且广受好评的 JavaScript 学习平台链接地址如下所示: - Codecademy: https://www.codecademy.com/learn/introduction-to-javascript - FreeCodeCamp:https://www.freecodecamp.org/ - LeetCode :https://leetcode-cn.com/problemset/all/?topicSlugs=javascipt - Hackerrank:https://www.hackerrank.com/domains/tutorials/10-days-of-javascript - Codewars:https://www.codewars.com/kata/search/javascript?q=&beta=false&order_by=popularity%20desc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值