@@ -0,0 +1,1149 @@
+#!/usr/bin/env python%0A%0Afrom __future__ import print_function%0Afrom collections import deque%0A%0Adef get_last_word(s):%0A    word_q = deque()%0A    for letter in s:%0A        if len(word_q) == 0:%0A            word_q.append(letter)%0A        elif letter %3E= word_q%5B0%5D:%0A            word_q.appendleft(letter)%0A        else:%0A            word_q.append(letter)%0A    return ''.join(word_q)%0A%0Aif __name__ == '__main__':%0A    samples = %5B'CAB',%0A               'JAM',%0A               'CODE',%0A               'ABAAB',%0A               'CABCBBABC',%0A               'ABCABCABC',%0A               'ZXCASDQWE'%5D%0A    for sample in samples:%0A        print(get_last_word(sample))%0A%0A    data_files = %5B'A-small-practice', 'A-large-practice'%5D%0A    for f in data_files:%0A        with open('%7B0%7D.in'.format(f), 'r') as input_file:%0A            lines = input_file.readlines()%0A        input_count = int(lines%5B0%5D.replace('%5Cn' ,''))%0A        inputs = %5Bline.replace('%5Cn', '') for line in lines%5B1:%5D%5D%0A%0A        i = 1%0A        with open('%7B0%7D.out'.format(f), 'w') as output_file:%0A            for in_ in inputs:%0A                output_file.write('Case #%7B0%7D: %7B1%7D%5Cn'.format(i, get_last_word(in_)))%0A                i += 1%0A

Add the last word