【日付セット】13日の金曜日(4桁) (paizaランク C 相当) 解答例 – PHP編【paiza】
【日付セット】 > 13日の金曜日(4桁) (paizaランク C 相当)
※リンク先へ移動する為には「paiza」へのログインが必要です。
なんでこの問題だけこんなに細かく計算しないと正解にならないんだろ?(;^ω^)
解答例
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<?php $year = 1800; $month = 1; $day = 1; $nextyear = 2200; $nextmonth = 1; $nextday = 1; $counter = 12*400; $friday = 0; $date = $year."/".$month."/".$day; $date = strtotime($date); $date = date("Y/n/j/D",$date); $test = explode("/",$date); $year = $test[0]; $month = $test[1]; $day = $test[2]; $week = $test[3]; if($week == "Fri" && $day ==13){ $friday++; } while($year != $nextyear || $month != $nextmonth || $day != $nextday){ $date = $year."/".$month."/".$day; $date = strtotime($date."+1 day"); $date = date("Y/n/j/D",$date); $test = explode("/",$date); $year = $test[0]; $month = $test[1]; $day = $test[2]; $week = $test[3]; if($week == "Fri" && $day ==13){ $friday++; } } $counter--; $ans = floor(($friday / $counter)*10000)/10000; echo $ans; ?> |