#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. 禁止多行文本框textarea拖拽

    禁止多行文本框textarea拖拽: textarea { resize: none; } resize这个是用于元素缩放,它可以取以下几个值: none 默认值 both 允许水平方向及垂直方向缩放 ...

  2. 猜数字-js

    var n = Math.round(Math.random()*10); //随机数 // alert(n); while(true){ var Onum = prompt('请输入1-10之间的数 ...

  3. ubuntu 下 github 使用方法 以及异常修改

    接触github很长时间了,github有windows 跟 mac 版本,恶心的是现在在linux 下没有可视化界面的版本.所以对于很多没有怎么接触过github的人带来很大困难.话不多说,彪重点: ...

  4. 虚拟机显卡分配过高的警告(Insufficient video RAM)

    最近机房挪机柜,网线拔拔插插,又在虚拟机上配置了网卡的各项设置,其中一个虚拟机的网站这两天经常无法访问, 于是关注了一下虚拟机的“事件”,发现另外一个跳转网站的警告: 于是去vmware的官网上找到了 ...

  5. VC++中调用cmd的集中方式

    1. system方法: 原型: int __cdecl system(const char *); 例如: system("ipconfig"); 2. WinExec方法: 相 ...

  6. Android Activity整体管理和关闭工具类封装

    如何彻底退出程序,在任意位置退出程序,如何管理当前的运行栈,知道activity的堆栈结构等,本文封装了一个Activity管理类,可以方便随时退出程序. /** * 应用程序Activity管理类: ...

  7. Linux系统编程(37)—— socket编程之原始套接字

    原始套接字的特点 原始套接字(SOCK_RAW)可以用来自行组装IP数据包,然后将数据包发送到其他终端.也就是说原始套接字是基于IP数据包的编程(SOCK_PACKET是基于数据链路层的编程).另外, ...

  8. delphi编写dll心得, 谢谢原作者的分享。转

    delphi编写dll心得 1.每个函数体(包括exports和非exports函数)后面加 'stdcall;', 以编写出通用的dll2.exports函数后面必须加'export;'(放在'st ...

  9. HDU4742----Pinball Game 3D(三维LIS、CDQ分治)

    题意:三维空间内 n个小球,对应坐标(x,y,z).输出LIS的长度以及方案数. 首先可以先按x排序,先降低一维,然后 剩下y .z,在y上进行CDQ分治,按y的大小用前面的更新后面的.z方向离散化之 ...

  10. 你需要知道的九大排序算法【Python实现】之冒泡排序

    二.冒泡排序 基本思想:它的思路很有特点循环,两两向后比较.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没有再需要交换,也就是说该数 ...