SHARE
TWEET

408 help

a guest Dec 11th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #задача изи но я не понял
  2. k,n = map(int,input().split())
  3. a = []
  4. ans = []
  5. can = True
  6. for i in range(n):
  7.     a.append(input())
  8.  
  9.  
  10. for word in a:
  11.     i = 0
  12.     left_count = 0
  13.     right_count = len(word)
  14.     left = True
  15.     right = True
  16.     for sym in word:
  17.         if left:
  18.             if sym == ' ':
  19.                 left_count += 1
  20.             else:
  21.                 left = False
  22.         else:
  23.             if sym == ' ' and right:
  24.                 right_count = i
  25.                 right = False
  26.             else:
  27.                 right = len(word)
  28.                 right = True
  29.         i += 1
  30.     wordx = word[left_count:right_count]
  31.     right_count = left_count = 0
  32.     len_word = len(wordx)
  33.     while len_word < k:
  34.         if left_count < right_count - 1:
  35.             left_count += 1
  36.             wordx = ' ' + wordx
  37.         else:
  38.             right_count += 1
  39.             wordx += ' '
  40.         len_word += 1
  41.     if right_count - 1 == left_count:
  42.         ans.append(wordx)
  43.     else:
  44.         can = False
  45.         break
  46.  
  47. if can:
  48.     for word in ans:
  49.         print(word)
  50. else:
  51.     print('Impossible.')
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