题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
#include <iostream> using namespace std; //更新顶部和底部位置 int main() { int n; char operation; cin>>n; int x=1; int top=1; int bottle=4; while(cin>>operation){ switch(operation){ case 'U':{ if(x==1) { x=n; top=n-3; bottle=n; } else if(x==top){ x--; top=x; bottle--; }else x--; break; } case 'D':{ if(x==n) { x=1; top=1; bottle=4; }else if(x==bottle){ x++; bottle=x; top++; }else x++; break; } } } if(n<=4){ int i=1; while(n--){ cout<<i++<<" "; } cout<<endl; } else cout<<top<<' '<<top+1<<' '<<top+2<<' '<<top+3<<endl; cout<<x<<endl; return 0; } // 64 位输出请用 printf("%lld")