测试用例给的结果不全,导致只能暴力枚举所有的计算方法。
The test results is not all of the answers, I calculte all of the results and output them.
# poke dictionary
pokedict={'A':1,'J':11,'Q':12,'K':13}
operators=['+','-','*','/']
def calto_24(pokeget): #type<pokrget>==list
outpoke=[] #output poke list
if 'joker' in pokeget or 'JOKER' in pokeget:
print('ERROR')
else:
pokelist=[]
for ss in pokeget:
if ss in pokedict:pokelist.append(pokedict[ss])
else:pokelist.append(int(ss))
for i in range(4):
for j in range(4):
if j!=i:
for k in range(4):
if k not in [i,j]:
indexs = [0, 1, 2, 3] # index list
indexs.remove(i)
indexs.remove(j)
indexs.remove(k)
m=indexs[0]
for op1 in operators:
if op1=='+':answer1=pokelist[i]+pokelist[j]
if op1=='-':answer1=pokelist[i]-pokelist[j]
if op1=='*':answer1=pokelist[i]*pokelist[j]
if op1=='/':answer1=pokelist[i]/pokelist[j]
for op2 in operators:
if op2=='+':answer2=answer1+pokelist[k]
if op2=='-':answer2=answer1-pokelist[k]
if op2=='*':answer2=answer1*pokelist[k]
if op2=='/':answer2=answer1/pokelist[k]
for op3 in operators:
if op3=='+':answer3=answer2+pokelist[m]
if op3=='-':answer3=answer2-pokelist[m]
if op3=='*':answer3=answer2*pokelist[m]
if op3=='/':answer3=answer2/pokelist[m]
if answer3==24:
outpoke.append(pokeget[i]+op1+pokeget[j]+op2+pokeget[k]+op3+pokeget[m])
if len(outpoke)==0:
print('NONE')
else:
for o in outpoke:print(o) #output all of the answers
inpoke=input().split()
calto_24(inpoke)
京公网安备 11010502036488号