Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __ __ __ __ __ __ 01
- 02 03 04 05 06 07 08
- 09 10 11 12 13 14 15
- 16 17 18 19 20 21 22
- 23 24 25 26 27 28 29
- 30 31 __ __ __ __ __
- <?php
- $handle = fopen("input.txt", "r");
- list($month,$year) = fscanf($handle, "%d %d");
- $time = mktime(0, 0, 0, $month, 1, $year);
- $countDayOfMonth = date('t', $time);
- $weekNum = date('w', $time) - 1;
- if ($weekNum < 0) $weekNum = 6;
- $countPlaces = (ceil(($countDayOfMonth + $weekNum) / 7) * 7 - ($countDayOfMonth + $weekNum)) + ($countDayOfMonth + $weekNum);
- $str = "";
- for($i = 1; $i <= $countPlaces; $i++)
- {
- if( ($i <= $weekNum) OR $i > ($countDayOfMonth + $weekNum))
- {
- $str .= "__ ";
- }else
- $str .= str_pad(($i - $weekNum), 2, '0', STR_PAD_LEFT) . " ";
- if(($i % 7) == 0)
- {
- $str = trim($str);
- if($i < $countPlaces)
- $str .= PHP_EOL;
- }
- }
- echo $str;
- fclose($handle);
Add Comment
Please, Sign In to add comment