【出力形式を指定して出力】STEP: 4 ペアの数値の入った表を罫線入りで出力 (paizaランク C 相当) – PHP編【標準出力メニュー】
【標準出力メニュー】 > 【出力形式を指定して出力】STEP: 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?php $input = explode(" ",trim(fgets(STDIN))); $row = $input[0]; $col= $input[1]; $a = $input[2]; $b = $input[3]; $word = "(".$a.", ".$b.")"; $counter =0; if($col == 1){ for($i = 0; $i < $row;$i++){ if($i != $row-1){ $test = $word; echo $test."\n"; $counter = mb_strlen($test); for($j = 0;$j < $counter;$j++){ echo "="; } echo "\n"; } else { $test = $word; echo $test; } } } if($col != 1){ for($i = 0; $i < $row;$i++){ $counter =0; for($j = 0; $j < $col;$j++){ if($j == 0){ $test = $word." |"; $count = mb_strlen($test); echo $test; $counter += $count; } elseif($j == $col-1){ $test = " ".$word; $count = mb_strlen($test); echo $test; $counter += $count; } else{ $test = " ".$word." |"; $count = mb_strlen($test); echo $test; $counter += $count; } } if($i != $row-1){ echo "\n"; for($z = 0;$z < $counter;$z++){ echo "="; } echo "\n"; } } } ?> |
