Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Created April 8, 2018 14:57
Show Gist options
  • Select an option

  • Save qkreltms/17f36df51bd949772dce401b3789bb03 to your computer and use it in GitHub Desktop.

Select an option

Save qkreltms/17f36df51bd949772dce401b3789bb03 to your computer and use it in GitHub Desktop.
def f(n, seq):
print("Simulation %d" % ctn)
cache = []
for i in seq:
for j in i:
if j is "!":
print(''.join(reversed(cache)))
continue
if j in cache:
cache.pop(cache.index(j))
if len(cache) >= n:
cache.pop()
cache.insert(0, j)
ctn = 1
while True:
user = list(input().split())
if user[0] is '0':
break
n, seq = user
f(int(n), seq)
ctn += 1
@qkreltms
Copy link
Author

qkreltms commented Apr 8, 2018

설명

  1. 캐시에 넣기전 캐시에 이미 아이템이 있는지 확인
    있으면 해당 아이템 삭제
  2. 캐시의 길이를 벗어나면 젤 나중에 들어온걸 삭제
  3. 아이템을 넣는다.
    (1~3 반복...)
  4. '!'를 만나면 출력한다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment