Editorial for ECOO '21 P2 - DNA Derren


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Note that A is the only vowel. We can compare every pair of consecutive characters. If both are A, or neither are A, we need to insert a space. Otherwise, we should not.

The first subtask is intended to reward inefficient solutions that, for example, split the string and copy it. To implement this efficiently, we can simply loop through the string and output the spaces as we go, requiring no splitting or extra memory.

s = input()

for i in range(len(s)-1):
    print(s[i], end='')
    if (s[i] == 'A' and s[i+1] == 'A') or (s[i] != 'A' and s[i+1] != 'A'):
        print(' ', end='')
print(s[-1], end='')

Comments

There are no comments at the moment.