题解 | #MP3光标位置#
MP3光标位置
http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
def myfunc(num,disp_l,disp_n,orde):
if disp_l == [1,2,3,4] and disp_n == 1 and orde == 'U':
disp_l = [ i for i in range(num-3,num+1) ]
disp_n = num
elif disp_l == [i for i in range(num-3,num+1)] and disp_n == num and orde == 'D':
disp_l = [1,2,3,4]
disp_n = 1
elif disp_n == disp_l[0] and orde == 'U':
disp_l = [ i - 1 for i in disp_l ]
disp_n -= 1
elif disp_n == disp_l[-1] and orde == 'D':
disp_l = [ i + 1 for i in disp_l ]
disp_n += 1
elif orde == 'U':
disp_n -= 1
else:
disp_n += 1
return([disp_l,disp_n])
while True:
try:
number = int(input())
orders = input()
steps = 0
for i in orders:
if i == 'U':
steps += 1
else:
steps -= 1
if 0 < number <= 4:
display_list = [ i for i in range(1,number + 1)]
print(*display_list)
if steps % number == 0:
display_number = 1
else:
display_number = 1 + steps % number
print(display_number)
elif number > 4:
display_list = [1,2,3,4]
display_number = 1
for order in orders:
results = myfunc(number,display_list,display_number,order)
display_list,display_number = results[0],results[1]
print(*display_list)
print(display_number)
except:
break