#include <cstdio>
#include <iostream>
using namespace std; long long Median, arr[]; int main()
{
int i, cur_index, count, isOdd;
count = ;
while(scanf("%lld", &arr[]) != EOF) // arr[0] is a monitor
{
count ++; // count: caculate numbers
cur_index = count; // cur_index initial value: count
for(i=; i<count; i++)
{
if(arr[] < arr[i])
{
cur_index = i;
break;
}
} for(i=count; i>cur_index; i--) // backword move to arr[count]
arr[i] = arr[i-]; arr[cur_index] = arr[]; // whatever, this is must. isOdd = count % ;
if(isOdd)
Median = arr[count/ + ]; // odd
else Median = (arr[count/ +] + arr[count/]) / ; // even cout << Median << endl;
}
return ;
}

犯错:漏写 break; 语句

 //
#include <cstdio>
#include <iostream>
using namespace std; int main()
{
int x, i, j, arr[], n = ;
while(scanf("%d", &x) != EOF)
{
j = n;
for(i = ; i < n; i++)
if(x < arr[i])
{
j = i;
break;
}
for(i=n; i > j; i--)
arr[i] = arr[i-];
arr[j] = x;
n ++; if(n % ) cout << arr[n / ] << endl;
else {
long median = ;
median = median + arr[n / - ] + arr[n / ];
cout << median / << endl;
}
}
return ;
}

uva 10107 - What is the Median?的更多相关文章

  1. No.004:Median of Two Sorted Arrays

    问题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...

  2. [LeetCode] Find Median from Data Stream 找出数据流的中位数

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  3. [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  4. Applying vector median filter on RGB image based on matlab

    前言: 最近想看看矢量中值滤波(Vector median filter, VMF)在GRB图像上的滤波效果,意外的是找了一大圈却发现网上没有现成的code,所以通过matab亲自实现了一个,需要学习 ...

  5. 【leetcode】Median of Two Sorted Arrays

    题目简述: There are two sorted arrays A and B of size m and n respectively. Find the median of the two s ...

  6. Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing

    B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...

  7. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  8. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  9. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

随机推荐

  1. php 学习路线 赵兴壮2014年4月28 日 加油

    第一阶段 第一讲,WEB基础     1.1 网站基本知识: 1.2 网络协议介绍: 1.3 B/S与C/S结构的区别: 1.4 WEB编程.网站开发技术介绍.      第二讲,网页设计     2 ...

  2. str_repeat() 函数

    <?php echo str_repeat(".",13);//重复几次 ?>

  3. cocos2d(粒子效果编辑器)

    ParticleDesigner  for  Mac下载地址:http://www.cocoachina.com/bbs/read.php?tid=108339 最近在做一款粒子编辑器 其实就是在co ...

  4. WinMain与WndProc以及窗口诞生过程总结

    一.int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow) 四个 ...

  5. javaWeb防止恶意登陆或防盗链的使用

    使用场景:明明引用了一个正确的图片地址,但显示出来的却是一个红叉或写有“此图片仅限于***网站用户交流沟通使用”之类的“假图片”.用嗅探软件找到了多媒体资源的真实地址用下载软件仍然不能下载.下载一些资 ...

  6. spark Association failed with [akka.tcp:sparkMaster@ip:7077]

    今搭建spark集群, conf/spark-env.sh 配制如下 export SPARK_MASTER_IP=masterexport SPARK_MASTER_PORT=7077export ...

  7. java交通灯管理系统项目

    交通灯管理系统   模拟实现十字路口的交通灯管理系统逻辑,具体需求如下: 异步随机生成按照各个路线行驶的车辆. 例如: 由南向而来去往北向的车辆 ---- 直行车辆 由西向而来去往南向的车辆 ---- ...

  8. 对编程语言的需求总结为四个:效率,灵活,抽象,生产率(C++玩的是前三个,Java和C#玩的是后两个)

    Why C++ ? 王者归来(转载) 因为又有人邀请我去Quora的C2C网站去回答问题去了,这回是 关于 @laiyonghao 的这篇有点争议的博文<2012 不宜进入的三个技术点>A ...

  9. FMX手机app,如何下载网站图片而不卡界面

    你用的版本? 你应该关注下delphi 更新说明第一方法: 可以用线程.第二方法: TNetHTTPClient 已经支持异步 TThread.CreateAnonymousThread( proce ...

  10. 【Linux】部署apache

    部署前的准备: 1.安装apr #wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.8.tar.gz #tar -zxvf apr-1.4.8.tar. ...