fork download
  1. import sys
  2. matrix = []
  3. count = 0
  4. r, c, k = map(int, input().split())
  5. for _ in range(3):
  6. matrix.append(list(map(int, input().split())))
  7.  
  8. while matrix[r][c] == k:
  9. if count > 100:
  10. count = -1
  11. break
  12. count += 1
  13. nrow = len(matrix)
  14. ncol = len(matrix[0])
  15. new_matrix = []
  16. if nrow >= ncol:
  17. num_of_row = 0
  18. for i in matrix:
  19. temp_row = []
  20. temp_dict = {}
  21. for j in i:
  22. temp_dict[j] = temp_dict.get(j, 0)
  23. temp_dict[j] += 1
  24. for element in sorted(temp_dict.items()):
  25. num, num_count = element
  26. temp_row.append(num)
  27. temp_row.append(num_count)
  28. if num_of_row < len(temp_row):
  29. num_of_row = len(temp_row)
  30. new_matrix.append(temp_row)
  31. for idx, row in enumerate(new_matrix):
  32. if len(row) < num_of_row:
  33. for _ in range(num_of_row - len(row)):
  34. new_matrix[idx].append(0)
  35. matrix = new_matrix
  36. print(matrix)
  37. break
  38. # else:
  39.  
  40. print(count)
Success #stdin #stdout 0.02s 9404KB
stdin
1 2 3
1 2 1
2 1 3
3 3 3
stdout
[[1, 2, 2, 1, 0, 0], [1, 1, 2, 1, 3, 1], [3, 3, 0, 0, 0, 0]]
1