class maxMachine :
def __init__(self) :
self.num=[]
def addNumber(self, n) :
self.num.append(n)
def removeNumber(self, n) :
self.num.remove(n)
def getMax(self) :
return max(self.num)
main함수에서
n = int(input()) // n번 반복.
for i in range(n) :
line = [int(v) for v in input().split()]
if line[0] == 0 :
myMachine.addNumber(line[1])
elif line[0] == 1 :
myMachine.removeNumber(line[1])
elif line[0] == 2 :
print(myMachine.getMax())
class ListPipe:
def __init__(self) :
self.myPipe = []
def addLeft(self, n) :
self.myPipe.insert(0,n)
def addRight(self, n) :
self.myPipe.append(n)
def getBeads(self) :
return self.myPipe
def processBeads(myInput) :
myPipe = ListPipe()
for bead, direction in myInput:
if(direction == 0):
myPipe.addLeft(bead)
elif(direction == 1):
myPipe.addRight(bead)
result = myPipe.getBeads()
return result
class LinkedListElement :
def __init__(self, val, ptr) :
self.value = val # 정수
self.myNext = ptr # 또 다른 element
class LinkedListPipe:
def __init__(self) :
'''
리스트 myPipe를 만듭니다. 이는 구슬의 배치를 저장합니다.
'''
# 연결 리스트의 시작 정점과 끝 정점을 가리키는 것이 각각
# start, end인데 얘들을 none으로 초기화
# 즉, 한마디로 초기화임...
self.start = None
self.end = None
self.mypipe = []
def addLeft(self, n) :
'''
파이프의 왼쪽으로 구슬 n을 삽입합니다.
'''
if self.start == None and self.end == None:
# == 비어있다.
elem = LinkedListElement(n,None)
self.start = elem
self.end = elem
else:
elem = LinkedListElement(n, self.start)
# 새로 변경..
self.start = elem
def addRight(self, n) :
'''
파이프의 오른쪽으로 구슬 n을 삽입합니다.
'''
if self.start == None and self.end == None:
# == 비어있다.
elem = LinkedListElement(n,None)
self.start = elem
self.end = elem
else:
elem = LinkedListElement(n, None)
# 새로 변경..
self.end.myNext = elem
self.end = elem
def getBeads(self) :
'''
파이프의 배치를 list로 반환합니다.
'''
result = []
# 현재 노드
current = self.start
while current != None:
result.append(current.value)
current = current.myNext
return result
def processBeads(myInput) :
myPipe = LinkedListPipe()
for bead, direction in myInput:
if(direction == 0):
myPipe.addLeft(bead)
elif(direction == 1):
myPipe.addRight(bead)
result = myPipe.getBeads()
return result
myPipe = LinkedListPipe()
result = []
return result
class maxMachine :
def __init__(self) :
self.num=[]
def addNumber(self, n) :
self.num.append(n)
def removeNumber(self, n) :
self.num.remove(n)
def getMax(self) :
return max(self.num)
def sorting(myList) :
myMachine = maxMachine()
result = []
for i in myList:
myMachine.addNumber(i)
for i in range(len(myList)):
mymax = myMachine.getMax()
result.append(mymax)
myMachine.removeNumber(mymax)
return result
class orderManager :
def __init__(self) :
self.data = []
def addOrder(self, orderId) :
self.data.append(orderId)
def removeOrder(self, orderId) :
self.data.remove(orderId)
def getOrder(self, orderId) :
for i in range(len(self.data)):
if self.data[i] == orderId:
return (i+1)
return -1
class LinkedListElement :
def __init__(self, data, myPrev, myNext) :
self.data = data
self.myPrev = myPrev
self.myNext = myNext
class orderManager :
def __init__(self) :
self.start = None
self.end = None
def addOrder(self, orderId) :
o = LinkedListElement(orderId, None, None)
if self.start == None and self.end == None:
self.start = o
self.end = o
else:
self.end.myNext = o
o.myPrev = self.end
self.end = o
def removeOrder(self, orderId) :
if self.start == None and self.end == None:
return
current = self.start
while current != None:
if current.data == orderId:
prevElem = current.myPrev
nextElem = current.myNext
if prevElem != None:
prevElem.myNext = nextElem
if nextElem != None:
nextElem.myPrev = prevElem
if current == self.end:
self.end = prevElem
if current == self.start:
self.start = nextElem
current = current.myNext
def getOrder(self, orderId) :
cnt=0
if self.start == None and self.end == None:
return -1
current = self.start
while current != None:
if current.data == orderId:
return cnt + 1
current = current.myNext
cnt += 1
return -1
class LinkedListElement :
def __init__(self, data, myPrev, myNext) :
self.data = data
self.myPrev = myPrev
self.myNext = myNext
class orderManager :
def __init__(self) :
self.start = None
self.end = None
self.elems = {} #주문번호를 저장하는 딕셔너리.
def addOrder(self, orderId) :
elem = LinkedListElement(orderId, None, None)
self.elems[orderId] = elem
if self.start == None and self.end == None:
self.start = elem
self.end = elem
else:
self.end.myNext = elem
elem.myPrev = self.end
self.end = elem
def removeOrder(self, orderId) :
if self.start == None and self.end == None:
return
# 전에는 while문을 돌려가며 찾았지만 지금은 cur에 바로 집어 넣음.
cur = self.elems[orderId]
if self.start == cur and self.end == cur:
self.start = None
self.end = None
elif self.start == cur:
self.start = cur.myNext
(cur.myNext).myPrev = None
elif self.end == cur:
self.end = cur.myPrev
(cur.myPrev).myNext = None
else:
cur.myPrev.myNext = cur.myNext
cur.myNext.myPrev = cur.myPrev
def getOrder(self, orderId) :
cnt = 1
cur = self.start
while cur != None:
if cur.data == orderId:
return cnt
cur = cur.myNext
cnt = cnt + 1
return -1
list object cannot be interpreted as an integer
주로 for문의 range함수를 쓸 때 나오는데 range함수 안에 배열만 짚어넣고 안된다고 한다. len을 넣어야만 해결 가능.