MP3光标移动
#include<iostream> #include<string.h> using namespace std; int main() { int N; cin>>N; int first = 1; int last = N; int start = 1; int length = 4; int curr = 1; char str[100]; cin>>str; int num = strlen(str); for(int i=0; i<num; i++) { char ch = str[i]; if(ch=='U') { if(curr == first) { start = N<=4 ? start : last - 3; curr = N; } else if(curr == start) { start = N<=4 ? start : start - 1; curr = start; } else { curr = curr-1; } } else if(ch=='D') { if(curr == last) { start = 1; curr = 1; } else if(curr == start+length-1) { start = start + 1; curr = curr+1; } else { curr = curr+1; } } else { } } for(int i=start; i<start+4; i++) { if(i<=last) { cout<<i; if(i!=start+3 && i!= last) { cout<<' '; } } } cout<<endl<<curr<<endl; return 0; }