-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccc01s2.py
More file actions
59 lines (49 loc) · 1.44 KB
/
ccc01s2.py
File metadata and controls
59 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
n = int(input())
for x in range(n):
temp = [int(x) for x in input().split(" ")]
curr = temp[0]
end = temp[1]
grid = [[curr]]
moves = 0
curr += 1
while (curr <= end):
if (moves % 2 == 0):
if (moves % 4 == 0):
temp = len(grid)
for i in range(temp-1):
grid[i+1].insert(0, " ")
for i in range(temp-1):
grid[i+1][0] = curr
curr += 1
grid.append([curr])
curr += 1
else:
temp = len(grid)
for i in range(temp-1):
grid[temp-i-2].append(curr)
curr += 1
grid.insert(0, [curr])
curr += 1
else:
if (moves % 4 == 1):
temp = len(grid[0])
for i in range(temp):
grid[-1].append(curr)
curr += 1
else:
temp = len(grid[0])
for i in range(temp+1):
grid[0].insert(0, curr)
curr += 1
moves += 1
for i in range(len(grid[1]) - len(grid[0])+1):
grid[0].insert(0, " ")
for row in grid:
for col in row:
if col != " " and col > end:
row.remove(col)
for row in grid:
for col in row:
print(col, end=" ")
print("")
print("")