CPTTRN1

来源:互联网 发布:第八届云计算大会ppt 编辑:程序博客网 时间:2024/06/08 05:34
CPTTRN1 - Character Patterns (Act 1)
#basics
Using two characters: . (dot) and * (asterisk) print a chessboard-like pattern. The first character printed should be * (asterisk).

Input

You are given t < 100 - 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 in the pattern (l, c < 100).

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");while($some=trim(fgets($hi,100))){list($a, $b) = explode(' ', $some);if($a&&$b){for($i=0;$i<$a;$i++){for($j=0;$j<$b;$j++){if(($i%2==0 && $j%2==0)||($i%2==1 && $j%2==1) )fwrite($ho,  "*");elsefwrite($ho,  ".");}fwrite($ho,  "\n");}}elsecontinue;fwrite($ho,  "\n");}fclose($ho);fclose($hi);


我的解法二:

<?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(($k%2==0 && $j%2==0)||($k%2==1 && $j%2==1))fwrite($ho,  "*");elsefwrite($ho,  ".");}fwrite($ho,  "\n");}fwrite($ho,  "\n");}fclose($ho);fclose($hi);?>