题解 | #MP3光标位置#
MP3光标位置
http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
try:
n = int(input())
option = input()
total_lst = [i for i in range(1, n + 1)]
cursor = 0
if n > 4:
cur_lst = total_lst[:4]
for op in option:
if op == 'U':
if cursor == 0:
if cur_lst[0] == total_lst[0]:
cursor = 3
cur_lst = total_lst[-4:]
else:
for i in range(4):
cur_lst[i] -= 1
else:
cursor -= 1
else:
if cursor == 3:
if cur_lst[3] == total_lst[-1]:
cursor = 0
cur_lst = total_lst[:4]
else:
for i in range(4):
cur_lst[i] += 1
else:
cursor += 1
else:
cur_lst = total_lst
for op in option:
if op == 'U':
if cursor == 0:
cursor = n - 1
else:
cursor -= 1
else:
if cursor == n - 1:
cursor = 0
else:
cursor += 1
print(' '.join(str(i) for i in cur_lst))
print(cur_lst[cursor])
except:
break