Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. k,n = map(int,input().split())
  2. a = []
  3. ans = []
  4. can = True
  5. for i in range(n):
  6.     a.append(input())
  7.  
  8.  
  9. for word in a:
  10.     i = 0
  11.     left_count = 0
  12.     right_count = len(word)
  13.     left = True
  14.     right = True
  15.     for sym in word:
  16.         if left:
  17.             if sym == ' ':
  18.                 left_count += 1
  19.             else:
  20.                 left = False
  21.         else:
  22.             if sym == ' ' and right:
  23.                 right_count = i
  24.                 right = False
  25.             else:
  26.                 right = len(word)
  27.                 right = True
  28.         i += 1
  29.     wordx = word[left_count:right_count]
  30.     right_count = left_count = 0
  31.     len_word = len(wordx)
  32.     while len_word < k:
  33.         if left_count < right_count - 1:
  34.             left_count += 1
  35.             wordx = ' ' + wordx
  36.         else:
  37.             right_count += 1
  38.             wordx += ' '
  39.         len_word += 1
  40.     if right_count - 1 == left_count:
  41.         ans.append(wordx)
  42.     else:
  43.         can = False
  44.         break
  45.  
  46. if can:
  47.     for word in ans:
  48.         print(word)
  49. else:
  50.     print('Impossible.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement