It97 서울에서 김서방 찾기 def solution(seoul): count=0 for i in seoul: if i == 'Kim': break else: count+=1 answer = '김서방은 '+str(count)+"에 있다" return answer 2022. 7. 29. 2089번 : -2진수 # -2진수 n=int(input()) answer='' if n==0: print(0) while n!=0: if n%-2 == -1: n=n//-2+1 answer='1'+answer else: n//=-2 answer='0'+answer print(answer) 2022. 7. 23. 10866번 : 덱 # 덱 import sys n=int(sys.stdin.readline()) Deque=[] for i in range(n): order=sys.stdin.readline().split() if order[0]=="push_front": Deque.insert(0, order[1]) elif order[0]=="push_back": Deque.append(order[1]) elif order[0]=="pop_front": if len(Deque) != 0: print(Deque[0]) del(Deque[0]) else: print(-1) elif order[0]=="pop_back": if len(Deque) != 0: print(Deque[-1]) del(Deque[-1]) else: print(-1).. 2022. 7. 22. 10845번 : 큐 # 큐 import sys queue=[] n=int(sys.stdin.readline()) for i in range(n): order= sys.stdin.readline().split() if order[0]=="push": queue.append(order[1]) elif order[0]=="pop": if len(queue) !=0: print(queue[0]) del(queue[0]) else: print(-1) elif order[0]=="size": print(len(queue)) elif order[0]=="empty": if len(queue)==0: print(1) else: print(0) elif order[0]=="front": if len(queue) != 0: print(que.. 2022. 7. 21. 이전 1 2 3 4 ··· 25 다음