Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x, y = map(int, input().split())
- password = []
- a = []
- for i in range(x):
- s = input()
- for j in s:
- a.append(j)
- password.append(a)
- a = []
- l = int(input())
- b = [password[0][0]]
- i, j = 0, 0
- while i + 1 != x and j != y:
- if i + 1 < x and j + 1 < y:
- if x - i - 1 + y - j - 1 == l:
- if password[i + 1][j] > password[i][j + 1]:
- b.append(password[i + 1][j])
- i += 1
- else:
- b.append(password[i][j+1])
- j += 1
- else:
- if password[i + 1][j] < password[i][j + 1]:
- b.append(password[i + 1][j])
- i += 1
- else:
- b.append(password[i][j+1])
- j += 1
- else:
- if i + 1 >= x:
- if j + 1 < y:
- b.append(password[i][j + 1])
- j += 1
- else:
- b.append(password[i + 1][j])
- i += 1
- print(b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement