Advertisement
regergr

Untitled

Jan 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. f = open('input.txt')
  2. f_out = open('output.txt', 'w')
  3. d = []
  4. for line in f:
  5. if (line[1:3] in d) or ((d == []) and (line[0] == '/')) or ((d == []) and (line[0] == '^')):
  6. f_out.write('ERROR')
  7. exit()
  8. if (line[0] == '+'):
  9. d.insert(0, line[1:3])
  10. elif (line[0] == '#'):
  11. d.append(line[1:3])
  12. elif (line[0] == '^'):
  13. d.pop(0)
  14. elif (line[0] == '/'):
  15. d.pop()
  16. if (not d):
  17. f_out.write('EMPTY')
  18. else:
  19. f_out.write(' '.join(d))
  20. f.close()
  21. f_out.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement