2nd day

<?php
//求数组的平均值
    $a3 = array(
    array(11,12, 13),
    array(21,22,23, 24, 25),
    array(31,32,33, 35),
    array(41,42,43)
);
    $length = count($a3);
    $count = 0;
    $sum = 0;
    for($i=0; $i<$length; ++$i){
            $length2 = count($a3[$i]);
            for($j=0; $j<$length2; ++$j){
                    $sum += $a3[$i][$j];
                    ++$count;
                }
        }
    $average = $sum / $count;
    echo "数组的平均值是:$average";
    echo "<hr>";

    //一个“不整齐”数字数组,如下所示,求其平均值:
    $a4 = array(
    1,
    array(21,22,23, 24, 25),
    3,
    array( 41, 42, 43,array(50,  51,  52) )
);
    $sum = 0;
    $count = 0;
    function digui($arr){
        $length = count($arr);
        for($i=0; $i<$length; ++$i){
            $length2 = count($arr[$i]);
            if($length2==1){
                $GLOBALS[‘sum‘] += $arr[$i];
                ++$GLOBALS[‘count‘];
            }
            else{
                 digui($arr[$i]);
            }
        }
        return $GLOBALS[‘sum‘]/$GLOBALS[‘count‘];
    }
    $a = digui($a4);
    echo $a;
    echo ‘<hr>‘;

    //求一个整数数组中的最小的奇数,如果没有奇数,则直接输出“没有奇数”,否则输出该数。
    $arr = array(56,76,4,98,6,3,5);
    $length = count($arr);
    for($i=0; $i<$length; ++$i){
        if($arr[$i]%2!=0){
            $arr2[]=$arr[$i];
        }
    }
    if(!empty($arr2)){
        $min = $arr2[0];
        for($j=0; $j<count($arr2); ++$j){
            if($min>$arr2[$j]){
                $min = $arr2[$j];
            }
        }
        echo "最小的奇数为:$min";
    }
    else{
        echo "大哥,没有奇数!";
    }

?>
时间: 2024-12-14 20:13:51

2nd day的相关文章

从Pitre《Swift 基础教程2nd》开始

看了两天<Learn Objective-C on the MAC> 中文版本<Objective-C基础编程>,大概认真读到了第9章内存管理部分,感觉这语言可比C++简单多了. 第一天,因为有C语言基础的缘故,我在windows 上安装了GNUstep (Objective-C)开发环境,变看电子书籍,边在PC上编译运行树上的示例,几乎一个都没放过,还做了不少笔记. (毕竟作者 Mark Dalrymaple & Scott Knaster 是高屋建瓴,叙述技术娓娓道来,

BestCoder 2nd Anniversary的前两题

Oracle Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 79    Accepted Submission(s): 41 Problem Description There is once a king and queen, rulers of an unnamed city, who have three daughters

Elasticsearch Server,2nd Edition pdf 翻译 中文

很偶然的机会,就需要接触到搜索,入门就是google trend已然超过solr的ES.在入门的时候找书的时候发现没有中文版的.于是自己开始翻译Elasticsearch Server,2nd Edition.应该是全球头一份了.看到微博上已经有出版社把英文书引过来,刚找到了人翻译这本书.我就先放出来自己翻的一部分.如果他真找到这里来了,就义务提供一下自己翻译的资源: 翻译是同步在我的Evernote里.贴出来到blog里样式都乱了.索性分享出来我的Evernote.去看去吧. 如果要引用或者转

BestCoder 2nd Anniversary

http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+2nd+Anniversary&source=1&searchmode=source A 取最小的非零数,再相加 1 // #pragma comment(linker, "/STACK:102c000000,102c000000") 2 #include <iostream> 3 #include <cstdio>

HDU 5720 Wool BestCoder 2nd Anniversary (区间覆盖)

Wool Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 686    Accepted Submission(s): 192 Problem Description At dawn, Venus sets a second task for Psyche. She is to cross a river and fetch gol

armstrong&#39;s programming erlang 2nd

Re: json handling map functions in erlang 17 I have not read Joes final book on the matter (several drafts though) .. and I've told him, twice I think, that there will *not* be any maps to json BIFs to in the maps module. It does not belong in the st

HDU 5719 BestCoder 2nd Anniversary Arrange (DP)

Arrange Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 558    Accepted Submission(s): 198 Problem Description Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen

Otto Product Classification Winner&#39;s Interview: 2nd place, Alexander Guschin &#175;\_(ツ)_/&#175;

Otto Product Classification Winner's Interview: 2nd place, Alexander Guschin ¯\_(ツ)_/¯ The Otto Group Product Classification Challenge made Kaggle history as our most popular competition ever. Alexander Guschin finished in 2nd place ahead of 3,845 ot

2nd, 基本元素

Directives: directive是嵌入到源码中的命令,由汇编编译器识别和执行. 而 Instruction是在运行时被执行的. 例如, .data 属于 directive , 而 mov , add 属于Instruction. 对统一架构的处理器来说,Instruction对所有的汇编编译器都是相同的.但是汇编编译器的diretive却完全不同. MASM定义段的directives: 代码段: .CODE  ;  数据段: .DATA   ;  栈: .STACK ,如  .st

【HDU5721 BestCoder 2nd AnniversaryD】【平面最近点对 分治写法+KD-tree写法】Palace 平面最近点对

Palace Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 260    Accepted Submission(s): 72 Problem Description The last trial Venus imposes on Psyche is a quest to the underworld. She is to tak