题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
int result = 1;
if (n <= 4) {
for (auto ch : str) {
if (ch == 'U' ) {
if (result == 1) result = n;
else result--;
} else {
if (result == n) result = 1;
else result++;
}
}
for (int i = 1; i <= n; i++) cout << i << ' ';
cout << endl << result;
} else {
int top = 1, down = 4;
for (auto ch : str) {
if (ch == 'U' ) {
if (result == 1){
result = n;
down = n;
top = n - 3;
}
else if (result == top){
result--;
down--;
top--;
}
else result--;
} else {
if (result == n){
result = 1;
down = 4;
top = 1;
}
else if (result == down){
result++;
down++;
top++;
}
else result++;
}
}
for (int i = top; i <= down; i++) cout << i << ' ';
cout << endl << result;
}
}
// 64 位输出请用 printf("%lld")
