题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
#include <iostream> using namespace std; int head = 1; int opRe(char op,int pos,int num){ if(pos==1 && op=='U'){ if(num<=4) head=1; else head=num-3; return num; }else if(pos==num && op=='D'){ if(num<=4) head=1; else head=1; return 1; }else if(op=='D'){ if(pos+1-head>3){ head++; } return pos+1; }else{ if(pos==head){ head--; } return pos-1; } } int main(){ int num; std::cin >> num; string op; std::cin >> op; int res=1; for(auto ch:op){ res=opRe(ch,res,num); } int list = min(4,num); for(int j=head;j<head+list;j++){ std::cout << j << " "; } std::cout << std::endl; std::cout << res << std::endl; return 0; }