반응형
def solution(arr):
dic={}
li=[]
for i in arr:
if i not in dic:
dic[i]=1
else:
dic[i]+=1
for key, value in dic.items():
if value>1:
li.append(value)
if len(li)==0:
li.append(-1)
answer=li
return answer
print(solution([3,5,7,9,1]))
def solution(param):
dic={'BOOL':1, 'SHORT':2, 'FLOAT':4, 'INT':8, 'LONG':16}
st=''
li=''
cnt=0
for i in param:
cnt+=dic[i]
if cnt>128:
return 'HALT'
for i in param:
if i=='BOOL':
if len(li)<8:
li+='#'
else:
st=st+','+li
li='#'
if i=='SHORT':
if len(li)%2==1:
li+='.'
if len(li)<7:
li+='#'*dic[i]
else:
st=st+','+li
li='#'*dic[i]
if i=='FLOAT':
if len(li)%4!=0:
li+='.'*(4-len(li)%4)
if len(li)<5:
li+='#'*dic[i]
else:
st=st+','+li
li='#'*dic[i]
if i=='INT':
if len(li)%8!=0:
li+='.'*(8-len(li)%8)
if len(li)<1:
li+='#'*dic[i]
else:
st=st+','+li
li='#'*dic[i]
if i=='LONG':
if len(li)%8!=0:
li+='.'*(8-len(li)%8)
if len(li)<1:
st=st+','+'#'*8+','+'#'*8
else:
st=st+','+li
li=[]
st=st+','+'#'*8+','+'#'*8
answer=st.replace(',','',1)
return answer
print(solution(['INT','BOOL','FLOAT','SHORT','LONG']))
print(solution(['BOOL','INT','BOOL','SHORT','FLOAT','SHORT','LONG']))
후보키
def solution(relations):
answer = []
targets = [[i for i in range(len(relations[0]))]]
while targets:
check = 0
tmp = targets.pop(0)
for i in range(len(tmp)):
lst = []
for leng in range(len(relations)):
a = tmp.copy()
a.remove(tmp[i])
b = ''
for x in a:
b += relations[leng][x]
lst.append(b)
if (len(set(lst)) == len(lst)) and (a not in targets):
targets.append(a)
elif (len(set(lst)) != len(lst)):
check +=1
if check ==len(tmp):
answer.append(tmp)
return len(answer)
반응형