题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
#include <iostream> #include <string> using namespace std; int main() { int songNum; string op; cin >> songNum; //输入歌曲的数量 cin >> op; //输入操作码 int first = 1; //用于显示当前页的第一个歌曲 int curSong = 1; //当前歌曲记录 if (songNum <= 4) { for (int i = 1;i <= songNum;i++) { for (int j = 0;j < op.size();j++) { if (op[j] == 'U') //输入是up { if (curSong == 1) //如果当前歌曲是1 { curSong = songNum; } else { curSong -= 1; //当前歌曲减一 } } else if (op[j] == 'D') //输入是down { if (curSong == songNum) { curSong = 1; } else { curSong += 1; } } } } for (int i = 1;i <= songNum;i++) { cout << i << ' '; } cout << endl; cout << curSong << endl; } else { for (int j = 0;j < op.size();j++) { if (curSong == 1 && op[j] == 'U') { curSong = songNum; first = songNum - 3; } else if (curSong == songNum && op[j] == 'D') { curSong = 1; first = 1; } else if (curSong == first && op[j] == 'U') { curSong -= 1; first -= 1; } else if (curSong == first + 3 && op[j] == 'D') { first += 1; curSong += 1; } else if (op[j] == 'U') { curSong -= 1; } else { curSong += 1; } } for (int i = first;i <= first + 3;i++) { cout << i << ' '; } cout << endl; cout << curSong; } } // 64 位输出请用 printf("%lld")