#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. htmlspecialchars()函数

    htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体. 预定义的字符是: & (和号) 成为 & " (双引号) 成为 " ' (单引 ...

  2. 存储过程中update,然后用sql%判断update是否成功的存储过程

    --更新用户状态 PROCEDURE P_UPDATE_USER_STATUS ( v_SrcID IN NUMERIC, v_DstID IN NUMERIC, v_DstType IN NUMER ...

  3. MCS-51单片机存储器结构

    MCS-51的存储器可分为四类:  程序存储器 一个微处理器能够聪明地执行某种任务,除了它们强大的硬件外,还需要它们运行的软件,其实微处理器并不聪明,它们只是完全按照人们预先编写的程序而执行之.那么设 ...

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

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

  5. HDOJ 1420 Prepared for New Acmer(DP)

    Problem Description 集训进行了将近2个礼拜,这段时间以恢复性训练为主,我一直在密切关注大家的训练情况,目前为止,对大家的表现相当满意,首先是绝大部分队员的训练积极性很高,其次,都很 ...

  6. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  7. String和数字之间的转化

    主要是JDK的代码,还是比较的经典,值得一看,例如: package alg; /** * @author zha 字符串之间的转化 */ public class Alg3StringToint { ...

  8. android仿京东、淘宝商品详情页上拉查看详情

    话不多说,直接上干货,基本就是一个scrollview中嵌套两个scrollview或者webview;关键点事处理好子scrollview和父scrollview的触摸.滑动事件已达到想要的效果.大 ...

  9. POJ1017 packets

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48911   Accepted: 16570 Descrip ...

  10. Scala-逻辑判断

    package com.mengyao.scala.function /** * Scala的逻辑判断 * * @author mengyao */object Test2 { def main(ar ...