Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file = open('input.txt')
- stack = []
- s = ''
- for line in file:
- line = line.strip()
- if '+' in line:
- if line[1:] not in stack:
- stack.append(line[1:])
- else:
- s = 'ERROR'
- break
- elif '#' in line:
- if line[1:] not in stack:
- stack.insert(0, line[1:])
- else:
- s = 'ERROR'
- break
- elif line == '^':
- if len(stack) != 0:
- stack.pop(-1)
- else:
- s = 'ERROR'
- break
- elif line == '/':
- if len(stack) != 0:
- stack.pop(0)
- else:
- s = 'ERROR'
- break
- #print(stack)
- file.close()
- if s != 'ERROR' and len(stack) == 0:
- s = 'EMPTY'
- if s != 'ERROR' and s != 'EMPTY':
- stack.reverse()
- s = ' '.join(stack)
- file = open('output.txt', 'w')
- file.write(s)
- file.close()
Add Comment
Please, Sign In to add comment