spoj CPTTRN7 - Character Patterns (Act 7)

来源:互联网 发布:淘宝店铺动态在哪里看 编辑:程序博客网 时间:2024/06/02 03:29

Print a regular grid pattern with diamond-like base elements. Use the \ (backslash) and the / (slash) characters to print diamonds and . (dots) to fill the rest of the space.

Input

You are given t - the number of test cases and for each of the test cases three positive integers: r - the number of rows, c - the number of columns in the grid and s - the size of each diamond.

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:33 1 2 4 4 1 2 5 2Output:./\./..\\../.\/../\./..\\../.\/../\./..\\../.\/./\/\/\/\\/\/\/\//\/\/\/\\/\/\/\//\/\/\/\\/\/\/\//\/\/\/\\/\/\/\/./\../\../\../\../\./..\/..\/..\/..\/..\\../\../\../\../\../.\/..\/..\/..\/..\/../\../\../\../\../\./..\/..\/..\/..\/..\\../\../\../\../\../.\/..\/..\/..\/..\/.
思路:根据size来确定模

1、(row+col)%(2*size) = size - 1输出/

2、abs(row-col)%(2*size)=size输出\

3、否则输出.

注意:在循环中调用echo超时。将字符串拼凑完后, 再输出

<?php$str_n = fgets(STDIN);$n = (int)explode(' ', $str_n)[0];while ($n--){$line = fgets(STDIN);$data = explode(' ', $line);$r = intval($data[0]);$c = intval($data[1]);$size = intval($data[2]);$tmp = 2 * $size;$row = $r * $tmp;$col = $c * $tmp;$mod1 = $size - 1;$mod2 = $size;$ans = "";for ($i = 0; $i < $row; $i++){for ($j = 0; $j < $col; $j++){if ($mod1 == ($i + $j) % $tmp){$ans .= '/';}else if ($mod2 == abs($i - $j) % $tmp){$ans .= '\\';}else       {$ans .= '.';}} $ans .=PHP_EOL; }echo($ans);}



0 0
原创粉丝点击