Blogger Information
Blog 34
fans 0
comment 0
visits 26721
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
100人,100个灯,现在灯是灭状态,这100人起来打开自己整数倍的灯,最后房间那个灯是亮着的?
罗盼的博客
Original
1511 people have browsed it

实例

<?php
header("content-type:text/html;charset=utf-8 ");
//100人,100个灯,现在灯是灭状态,这100人起来打开自己整数倍的灯,最后房间那个灯是亮着的
//取整的几个方法:ceil()向上取整,floor()去掉小数部分,round()四舍五入,intval()取整
$arr=array();
for($people=1;$people<=100;$people++){//人循环
    
    for($d=1;$d<=intval(100/$people);$d++){//对灯操作循环     
          array_push($arr,$people*$d);         
    }
}

$arr1 = array_count_values($arr);
array_walk($arr1,function ($value,$k){
    if($value%2 == 1){
        echo $k.'号灯亮着','<br>';
    }
    
})
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments