题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
#include <stdio.h>
#include <string.h>
int main() {
int n,i,j,pos=1;//pos指向光标位置
scanf("%d\n",&n);
char move[101];
int top=1;//显示页面的第一首歌曲
gets(move);
int tmp=n>4?4:n;
int len=strlen(move);
for(i=0;i<len;i++)
{
if(move[i]=='U')
{
if(pos==1)
{
pos=n;
top=n+1-tmp;//n不大于4的时候top=1
}else if(pos==top)
{
pos--;
top--;
}else{
pos--;
}
}
if(move[i]=='D')
{
if(pos==n)
{
pos=1;
top=1;
}else if(pos==top+3)
{
pos++;
top++;
}else{
pos++;
}
}
}
for(i=0;i<tmp;i++)
{
printf("%d ",top++);
}
printf("\n");
printf("%d",pos);
return 0;
}
