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
- spoj CPTTRN7 - Character Patterns (Act 7)
- spoj CPTTRN3 - Character Patterns (Act 3)
- spoj CPTTRN4 - Character Patterns (Act 4)
- spoj CPTTRN5 - Character Patterns (Act 5)
- spoj CPTTRN6 - Character Patterns (Act 6)
- spoj 16891 Character Patterns (Act 8)
- CPTTRN1 - Character Patterns (Act 1)
- CPTTRN2 - Character Patterns (Act 2)
- spoj 16892 Straight Line Spiral Pattern (Act 1)
- ACT
- 初识Q-Patterns - 7
- patterns
- patterns
- patterns
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- 【pwd】显示当前目录
- Error: EACCES: permission denied, access '/usr/local/lib/node_modules' npm ERR! at Error (native)
- poj 2503 trie树
- 每天一个linux命令(48):watch命令
- 【chage】修改账号或密码的有效期限
- spoj CPTTRN7 - Character Patterns (Act 7)
- 在windows下搭建hadoop工程(二)之 WordCount 作业测试
- java线程的几种状态
- Android apk大小优化之自我实践
- Unity实现滑页嵌套(解决ScrollRect嵌套冲突问题)
- JavaScript中call,apply,bind方法的总结。
- C#中的 int?是什么意思
- hdu 1151 匈牙利算法
- 数据库SQL优化大总结之 百万级数据库优化方案