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