Skip to content

Instantly share code, notes, and snippets.

@HyunsDev
Created March 1, 2021 01:54
Show Gist options
  • Save HyunsDev/ff97542bdde59b6f6df49b43dbc477c8 to your computer and use it in GitHub Desktop.
Save HyunsDev/ff97542bdde59b6f6df49b43dbc477c8 to your computer and use it in GitHub Desktop.
# 아스키 누나
### 입력
디버그 = False
누나_코드 = ""
###
# "누나" 출력 코드
# 눈나..나..나..........주.거......나..........주.거......나..........거.......나..........거..!누나..나..나..........거.....나..........거..나..........나..........거........!
# 오류 정의
class StackUnderflow(Exception):
def __str__(self):
return "StackUnderFlow"
# 스택 클래스
class Stack:
def __init__(self):
# 리스트로 구현
self.nuna = []
# 리스트 길이 반환
def __len__(self):
return len(self.nuna)
# 리스트를 텍스트로 반환
def __str__(self):
return str(self.nuna[::1])
# 원소 추가
def push(self, item):
self.nuna.append(item)
# 마지막 원소 꺼내기
def pop(self):
if not self.isEmpty():
return self.nuna.pop(-1)
else:
raise StackUnderflow
# 리스트 초기화
def clear(self):
self.nuna = []
# 자료 포함 여부 확인
def isContain(self, item):
return item in self.nuna
# 마지막 원소 반환
def peek(self):
if not self.isEmpty():
return self.nuna[-1]
else:
raise StackUnderflow
def isEmpty(self):
return len(self.nuna) == 0
def size(self):
return len(self.nuna)
# 변수 INIT
누나_모드 = 0
누나_깊이 = 0
누나_스택 = Stack()
# 철자 분리
누나_리스트 = list(누나_코드)
if 디버그:
print(누나_리스트)
# 코드 실행
for 누나 in 누나_리스트:
# . 처리
if 누나_모드 in (1,2,3):
if 누나 == ".":
누나_깊이 = 누나_깊이 + 1
else:
if 누나_깊이 == 0:
누나_깊이 = 1
if 누나_모드 == 1: # 나
누나_스택.push(누나_스택.pop() * 누나_깊이)
elif 누나_모드 == 2: # 주
누나_스택.push(누나_스택.pop() - 누나_깊이)
elif 누나_모드 == 3: # 거
누나_스택.push(누나_스택.pop() + 누나_깊이)
누나_모드 = 0
# 눈, 누 처리
if 누나 == "눈" or 누나 == "누":
누나_스택.push(1)
# 나 처리
elif 누나 == "나":
누나_모드 = 1
누나_깊이 = 0
누나_길이_메모리 = 0
# 주 처리
elif 누나 == "주":
누나_모드 = 2
누나_깊이 = 0
누나_길이_메모리 = 0
# 거 처리
elif 누나 == "거":
누나_모드 = 3
누나_깊이 = 0
누나_길이_메모리 = 0
# 하트 처리
elif 누나 == "💕":
누나_스택.push(누나_스택.pop() + 누나_스택.pop())
# 느낌표 처리
elif 누나 == "!":
print(chr(누나_스택.peek()), end="")
# 넘어가기
elif 누나 in (".", "\n"):
continue
else:
raise SyntaxError
# if 디버그:
# print(f"[{누나}] {누나_모드}, {누나_깊이}, {str(누나_스택)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment