# class school:# def __init__(self, x, y):# print('This is Initialize Function')# # self: 클래스 내에서 자유롭게 가져다가 쓸 수 있도록 하는 마법의 단어# self.x = x# self.y = y## def vol(self):# print('VOL')# print(self.x + self.y)## a,b = map(int, input().split())## x = school(a, b)# x.vol()'''FILO: First In, Last Outif condition {}else {}List = [0, 0, 0, 0, 0] # stack'''# 입력값에 0 없음# class stack:# def __init__(self, N):# self.N = N# self.list = []# for i in range(self.N):# self.list.append(0)# self.top = -1## def push(self, x):# if self.top < self.N -1:# self.list[self.top+1] = x# self.top += 1# else:# print("범위 넘어감")## def pop(self):# if self.top > -1:# self.list[self.top] = 0# self.top -= 1# else:# print("범위 넘어감")## def view(self):# for i in range(self.N):# if self.list[self.N-1-i] != 0:# print(self.list[self.N-1-i])# def is_empty(self):# num = 0# for i in range(self.N):# if self.list[i] == 0:# num += 1# if num == self.N:# print('Y')# else:# print('N')# def is_full(self):# num = 0# for i in range(self.N):# if self.list[i] == 0:# num += 1# if num == 0:# print('Y')# else:# print('N')#### n = int(input())# k = stack(n)## # for i in range(n):# while True:# x = input()# a1 = -1# for i in x:# if i == '(':# break# a1 += 1# if x[a1+2:-1] != '':# num = int(x[a1+2:-1])## s = x[:a1+1]# if s == "push":# k.push(num)# elif s == "pop":# k.pop()# elif s == "is_empty":# k.is_empty()# elif s == "is_full":# k.is_full()# elif s == "view":# k.view()class stack: def __init__(self): self.N = 205 self.printlist = [] self.list = [] for i in range(self.N): self.list.append(1.1) self.top = -1 self.printnum = 0 def push(self, x): if self.top < self.N -1: self.list[self.top+1] = x self.top += 1 def pop(self): if self.top > -1: self.list[self.top] = 0 self.top -= 1 def Top(self): if self.list[self.top] == 1.1: self.printlist.append(-1) self.printnum += 1 else: self.printlist.append(self.list[self.top]) self.printnum += 1 def size(self): self.printlist.append(self.top+1) self.printnum += 1 def empty(self): if self.top + 1 == 0: self.printlist.append("true") self.printnum += 1 else: self.printlist.append("false") self.printnum += 1n = int(input())k = stack()for i in range(n): x = input() if x.__contains__('push'): num = int(x[6:-2]) k.push(num) elif x.__contains__('pop'): k.pop() elif x.__contains__('top') == True: k.Top() elif x.__contains__('size') == True: k.size() elif x.__contains__("empty") == True: k.empty()for i in range(k.printnum): print(k.printlist[i])# string = 'Hello World'# print(string.__contains__('Hello'))# string = 'push( 5523423232355 )'# print(string[6:-2])
top of page
기능을 테스트하려면 라이브 사이트로 이동하세요.
2023.12.17.
2023.12.17.
댓글 0개
좋아요
댓글(0)
bottom of page