题解 | #MP3光标位置#
MP3光标位置
http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
while True: try: s1 = int(input()) s2 = list(input()) dic = {'U': -1, 'D': 1} res = [] num = 1 flag = 0 if s1 <= 4: flag = 1 for i in range(1, s1+1): res.append(i) if flag == 1: print(' '.join(str(i) for i in res)) for s in s2: num += dic[s] if num == 0: num = s1 elif num == s1+1: num = 1 print(num) if s1>4: flag=2 first=1 end=4 if flag==2: for k in range(len(s2)): num +=dic[s2[k]] if num==0:#向上突破1 num=s1 first=s1-3 end=s1 elif num ==s1+1:#向下突破底 num=1 first=1 end=4 elif num<=end and num >=first:#在first和end中移动,不变 continue elif num==first-1:#突破first first=first-1 end=end-1 elif num==end+1:#突破end first=first+1 end=end+1 res2=[y for y in range(first,end+1)] print(' '.join(str(l) for l in res2)) print(num)#输出 except: break