题目
链接:https://ac.nowcoder.com/acm/contest/6219/A
来源:牛客网
牛牛现在有n张扑克牌,每张扑克牌都有点数和花色两部分组成。点数为‘1’-‘9’的正整数,花色为’C’,‘D’,‘H’,‘S’'其中的一个,分别表示梅花、方块、红桃、黑桃。现在牛牛想按一定的顺序把这n张牌扔掉。扔牌顺序的规则如下1.:
1.如果现在还剩素数张牌,则将牌顶的牌扔掉
2.如果现在还剩非素数张牌,则将牌底的牌扔掉
牛牛想知道他的扔牌顺序是什么,请返回扔牌顺序的字符串
题解
class Solution:
def Orderofpoker(self , x ):
# write code here
import math
n = len(x)//2
top = 0 #顶部
bottom = len(x) #底部
ls = [] #用来存放弹出来的排
while n > 0:
if n not in [2,3,5,7]:
ls.append(x[bottom-2:bottom])
bottom-=2
else:
ls.append(x[top:top+2])
top += 2
n -= 1
return "".join(ls)