CPTTRN2 - Character Patterns (Act 2)
Using two characters: . (dot) and * (asterisk) print a frame-like pattern.
Input
You are given t - the number of test cases and for each of the test cases two positive integers: l - the number of lines and c - the number of columns of a frame.
Output
For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns.
Example
Input: 3 3 1 4 4 2 5 Output: * * * **** *..* *..* **** ***** *****
我的解题如下:
<?php
$hi = fopen('php://stdin', 'r');
$ho = fopen('php://stdout', 'w');
fscanf($hi, '%d', $num);
for($i=0;$i<$num;$i++)
{
$line = trim(fgets($hi,100));
list($left, $right) = explode(' ', $line);
for($j=0;$j<$left; $j++)
{
for($k=0;$k<$right; $k++)
{
if($j==0||$j==$left-1||$k==0||$k==$right-1)
fwrite($ho, "*");
else
fwrite($ho, ".");
}
fwrite($ho, "\n");
}
fwrite($ho, "\n");
}
fclose($ho);
fclose($hi);