Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def validate_step(step, i):
- if step in ['', '#']:
- print('COMPRESSION FAILED')
- sys.exit()
- else:
- print('STEP {}: {}'.format(i, step))
- str_words = input().split()
- if len(str_words) <= 0:
- print('COMPRESSION FAILED')
- sys.exit()
- # Word Elimination
- for i in range(len(str_words)):
- word = str_words[i]
- new_word = ''
- # add all alpha chars (and 12) to new word
- j = 0
- while j < len(word):
- char = word[j]
- if char.isalpha() or char == ' ':
- new_word += char
- else:
- if j+1 < len(word):
- if char == '1' and word[j+1] == '2':
- new_word += char + word[j+1]
- j += 1
- j += 1
- str_words[i] = new_word
- step = (' '.join(str_words)).strip()
- validate_step(step, 1)
- # Letter Conversion
- for i in range(len(str_words)):
- new_word = ''
- for char in str_words[i]:
- if char.lower() in ['a', 'e', 'i', 'o', 'u']:
- new_word += char.upper()
- else:
- new_word += char.lower()
- str_words[i] = new_word
- step = (' '.join(str_words)).strip()
- validate_step(step, 2)
- # Word Compression
- i = 0
- while i < len(str_words):
- if str_words[i] == '':
- del str_words[i]
- else:
- if i % 2 == 0: # odd
- str_words[i] = str_words[i][::2]
- else: # even
- str_words[i] = str_words[i][len(str_words[i]) // 2:]
- i += 1
- step = (' '.join(str_words[::2]) + '#' + ' '.join(str_words[1::2])).strip()
- validate_step(step, 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement