SHARE
TWEET

Untitled

a guest May 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. x, y = map(int, input().split())
  2.  
  3. password = []
  4. a = []
  5. for i in range(x):
  6.     s = input()
  7.     for j in s:
  8.         a.append(j)
  9.     password.append(a)
  10.     a = []
  11.  
  12. l = int(input())
  13.  
  14. b = [password[0][0]]
  15.  
  16. i, j = 0, 0
  17.  
  18. while i + 1 != x and j != y:
  19.     if i + 1 < x and j + 1 < y:
  20.         if x - i - 1 + y - j - 1 == l:
  21.             if password[i + 1][j] > password[i][j + 1]:
  22.                 b.append(password[i + 1][j])
  23.                 i += 1
  24.             else:
  25.                 b.append(password[i][j+1])
  26.                 j += 1
  27.         else:
  28.             if password[i + 1][j] < password[i][j + 1]:
  29.                 b.append(password[i + 1][j])
  30.                 i += 1
  31.             else:
  32.                 b.append(password[i][j+1])
  33.                 j += 1
  34.     else:
  35.         if i + 1 >= x:
  36.             if j + 1 < y:
  37.                 b.append(password[i][j + 1])
  38.                 j += 1
  39.         else:
  40.             b.append(password[i + 1][j])
  41.             i += 1
  42.  
  43. print(b)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top