题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
#include <iostream> #include <random> #include <string> #include <sys/types.h> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> m(n); for(int i=0;i<n;++i) m[i]=i+1; int cusor=0; int first=0; string s; cin >> s; for(char ch:s){ if(ch=='U'){ if(cusor==0){ cusor=n-1; if(n>4){ first=cusor-3; } } else{ --cusor; if(n>4&&cusor<first) first=cusor; } } else { if(cusor==n-1){ cusor=0; if(n>4) first=0; } else { ++cusor; if(n>4&&cusor>first+3) first++; } } } for(int i=first;i<min(first+4,n);++i) cout << m[i] << ' '; cout << endl; cout << m[cusor]; } // 64 位输出请用 printf("%lld")