zoukankan      html  css  js  c++  java
  • uva 10107

     1 #include <cstdio>
     2 #include <iostream>
     3 using namespace std;
     4 
     5 long long Median, arr[10010];
     6 
     7 
     8 int main()
     9 {
    10     int i, cur_index, count, isOdd;
    11     count = 0;
    12     while(scanf("%lld", &arr[0]) != EOF)    // arr[0] is a monitor
    13     {
    14         count ++;    // count: caculate numbers
    15         cur_index = count;    // cur_index initial value: count
    16         for(i=1; i<count; i++)
    17         {
    18             if(arr[0] < arr[i])
    19             {
    20                 cur_index = i;
    21                 break;
    22             }
    23         }
    24 
    25         for(i=count; i>cur_index; i--)    // backword move to arr[count]
    26             arr[i] = arr[i-1];
    27         
    28         arr[cur_index] = arr[0];    // whatever, this is must.
    29 
    30         isOdd = count % 2;
    31         if(isOdd)
    32             Median = arr[count/2 + 1];    // odd
    33         else Median = (arr[count/2 +1] + arr[count/2]) / 2;    // even
    34 
    35         cout << Median << endl;
    36     }
    37     return 0;   
    38 }

    犯错:漏写 break; 语句

     1 // 20160125
     2 #include <cstdio>
     3 #include <iostream>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int x, i, j, arr[10005], n = 0;
     9     while(scanf("%d", &x) != EOF)
    10     {
    11         j = n;
    12         for(i = 0; i < n; i++)
    13             if(x < arr[i])
    14             {
    15                 j = i;
    16                 break;
    17             }
    18         for(i=n; i > j; i--)
    19             arr[i] = arr[i-1];
    20         arr[j] = x;
    21         n ++;
    22 
    23         if(n % 2) cout << arr[n / 2] << endl;
    24         else {
    25             long median = 0;
    26             median = median + arr[n / 2 - 1] + arr[n / 2];
    27             cout << median / 2 << endl;
    28         }
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    05-流程控制
    04-基础语法3
    03-基础语法2
    SQLyog-证书密钥
    博客园美化系列__看板娘
    修改博客园模板样式【完美解决方案】
    Linux-Deepin 下开启SSH远程登陆
    Mui---自己利用Vue编写的表格
    canvas--操作步骤--属性
    Mui-打开手机相册
  • 原文地址:https://www.cnblogs.com/aze-003/p/5094542.html
Copyright © 2011-2022 走看看