spoj CPTTRN5 - Character Patterns (Act 5)
来源:互联网 发布:防身器材 淘宝 编辑:程序博客网 时间:2024/06/06 12:51
Using two characters: . (dot) and * (asterisk) print a grid-like pattern. The grid will have l lines, c columns, and each square shaped element of the grid will have the height and width equal to s.
Moreover, each of the grid elements will have a diagonal. The diagonal of the first square in the first line of the grid is directed towards down and right corner - use the \ (backslash) character to print it; while the next diagonal will be directed towards upper right corner - use the / (slash) character to print it. Print the successive diagonals alternately (please consult the example below).
Input
You are given t - the number of test cases and for each of the test case three positive integers: l - the number of lines, c - the number of columns in the grid and s - the size of the single square shaped element.
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 2 Output:*****\.**.\******./**/.******\.**.\***************\*/*\*/***********/*\*/*\***********\*/*\*/***********/*\*/*\***************************\.*./*\.*./*\.**.\*/.*.\*/.*.\******************./*\.*./*\.*./**/.*.\*/.*.\*/.*****************题意:给出行,列及方块的大小 ,输出如下的字符,每个方格的对角线为左上->右下,后序的相反
思路:1、row % (s+1) = 0 或者col%(s+1)=0输出*
2、(row+col)%(2*s+2) = 0输出\
3、(row-col)%(2*s+2)=0输出/
代码如下:
t = int(input())for cas in range(t): line = input(); a = line.split(' '); l = int(a[0]) c = int(a[1]) s = int(a[2]) row = l * (s + 1) + 1 col = c * (s + 1) + 1 for i in range(row): for j in range(col): if (0 == i % (s + 1) or 0 == j % (s + 1)): print('*', sep = '', end = '') elif (0 == (i + j) % (2 * s + 2)): print('/', sep = '', end = '') elif (0 == (i - j) % (2 * s + 2)): print('\\', sep = '', end = '') else: print('.', sep = '', end = '') print()
- spoj CPTTRN5 - Character Patterns (Act 5)
- spoj CPTTRN3 - Character Patterns (Act 3)
- spoj CPTTRN4 - Character Patterns (Act 4)
- spoj CPTTRN6 - Character Patterns (Act 6)
- spoj CPTTRN7 - Character Patterns (Act 7)
- 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
- javascript patterns CHAPTER 5 Object Creation Patterns
- Ajax Patterns 读书笔记 --5
- 初识Q-Patterns - 5
- patterns
- patterns
- patterns
- spoj 5 PALIN
- SPOJ
- Android 实现 session 保持
- Java连接数据库(学习笔记啦!)【整理网上的材料】
- sdau-2 1003
- Python与自然语言处理(二)基于Gensim的Word2Vec
- Servlet
- spoj CPTTRN5 - Character Patterns (Act 5)
- 1020
- SparkML之假设性检验(一)
- 算法之全排列
- Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
- Spring注解@Component、@Repository、@Service、@Controller区别
- PS里建立工作路径对话框中的“容差”是干什么的?
- 小马哥--高仿苹果6sp-主板型号Q39hd-m1刷机拆机图与开机界面图
- singleton和prototype的区别