题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
n = int(input()) ud = input().upper() p = 1 s = [] l = [] for i in ud: if i == 'U' and p == 1: p = n s.append(p) elif i == 'U': p = p - 1 s.append(p) elif i == "D" and p == n: p = 1 s.append(p) elif i == "D": p = p + 1 s.append(p) if n <= 4: for j in range(1, n+1): l.append(j) for k in l: print(k, end=' ') print() print(s[-1]) elif n > 4: s.reverse() for j in s: if j not in l: l.append(j) if len(ud) % n == 4 and s[0] == 1: print('1 2 3 4 ') print('1') elif s[0] and s[1] in range(n-3, n+1) and s[2] == 1: print(n-3, n-2, n-1, n) print(s[0]) else: for k in sorted(l[:4]): print(k, end=' ') print() print(l[0])