题解 | #24点运算#
24点运算
https://www.nowcoder.com/practice/7e124483271e4c979a82eb2956544f9d
#使用递归即可,和【HJ67 24点游戏算法】类似 def check(l,n): ss=[0,'A','2','3','4','5','6','7','8','9','10','J','Q','K'] if len(l)==1: if ss.index(l[0])==n: return l[0] else: return None else: for i in range(len(l)): ls=l[:i]+l[i+1:] m=ss.index(l[i]) if check(ls,m+n): return check(ls,m+n)+'-'+l[i] if check(ls,n-m): return check(ls,n-m)+'+'+l[i] if check(ls,n*m): return check(ls,n*m)+'/'+l[i] if check(ls,n/m): return check(ls,n/m)+'*'+l[i] while 1: try: l=input().split() if "joker" in l or "JOKER" in l: print("ERROR") else: ans=check(l,24) print(ans) if ans else print("NONE") except: break