牛客华为机试HJ35

原题传送门

1. 问题描述

2. Solution

1、思路分析
找规律
0 | 1 3 6 10
1 | 2 5 9
2 | 4 8
3 | 7

0 1 0 2 1 0 3

2、代码实现

import sys  if sys.platform != linux:     file_in = open(input/HJ35.txt)     sys.stdin = file_in   0 | 1 3 6 10 1 | 2 5 9 2 | 4 8 3 | 7  0 1 0 2 1 0 3    def solve(n):     result = [[] for _ in range(n)]     cur_row = 0     cnt = 1     row = -1     while len(result[0]) != n:         if cur_row == 0:             row += 1             cur_row = row         else:             cur_row -= 1         result[cur_row].append(cnt)         cnt += 1     for nums in result:         [print(x, end= ) for x in nums]         print()   for line in sys.stdin:     n = int(line.strip())     solve(n)