Python 2-583字节
我太新了,无法评论帖子,所以我只发布了我的python solusion版本。
解决了对和六分之三的“ es”问题。感谢Not that Charles
d={'A':['ace',14],'2':['two',2],'3':['three',3],'4':['four',4],'5':['five',5],'6':['six',6],'7':['seven',7],'8':['eight',8],'9':['nine',9],'T':['ten',10],'J':['jack',11],'Q':['queen',12],'K':['king',13]}
r=input()
j=1
i=lambda x:d[x][j]
v=sorted(r[::2],key=i)
z,y,x=v
s=r[1::2]
e='es'if i(y)==6else's'
j=0
a=i(x)
if z==y or y==x:r="pair of %s"%i(y)+e
if s[0]*3==s:r="%s flush"%a
t="%s-%s"%(i(z),i(y))
j=1
u=" on the bounce"if r[-1]=='h'else ""
if i(z)+i(x)==2*i(y):r=t+"-%s"%a+u
if ''.join(v)=="23A":r="%s-"%a+t+u
if [z]*3==v:r="three %s"%d[z][0]+e
if len(r)==6:r="%s high"%a
print r
带有一些注释的可读性更高
# first of all we don't need to keep suits
d={'A':['ace',14],'2':['two',2],'3':['three',3],'4':['four',4],'5':['five',5],'6':['six',6],'7':['seven',7],'8':['eight',8],'9':['nine',9],'T':['ten',10],'J':['jack',11],'Q':['queen',12],'K':['king',13]}
r=input() # input placed in r, to safely check r[-1] later in code
j=1 # j toggles reading from dictionary: 0-string, 1-value
i=lambda x:d[x][j] # lambda used to access dictionary
v=sorted(r[::2],key=i) # take values from input and sort
z,y,x=v # variables to compact code
s=r[1::2] # take suits from input
e='es'if i(y)==6else's' # choose ending 'es' for six and 's' for others (for pair and three)
j=0 # toggle reading from dictionary to string
a=i(x) # get string of top most value
if z==y or y==x: # check only two pairs as values are sorted
r="pair of %s"%i(y)+e
if s[0]*3==s: # compact check if all string characters are equal to detect flush
r="%s flush"%a
t="%s-%s"%(i(z),i(y)) # part of straight output - first two values
j=1 # toggle reading from dictionary to values
u=" on the bounce"\ # addon to output in case of possible straight flush
if r[-1]=='h'else "" # detected by checking last character in r
# which would be 'h' if flush was detected
if i(z)+i(x)==2*i(y): # check straight - three sorted numbers a,b,c would be in line if a+c == 2*b
r=t+"-%s"%a+u
if ''.join(v)=="23A": # check special case with straight, started from Ace
r="%s-"%a+t+u
j=0 # toggle reading from dictionary to string
if [z]*3==v: # check three equal values (almost the same as flush check)
r="three %s"%d[z][0]+e
if len(r)==6: # if r was never modified, then it's just one high card
r="%s high"%a
print r # output r