#include <stdio.h>
int cmd_up(int *current, int* cmd_up, int* cmd_down, int songs)
{
int flag = 0;
/* 首先移动当前歌曲光标位置 */
if(*current == 1)
{
(*current) = songs;
flag = 1;
}
else
{
(*current)--;
}
/* 当前歌曲为特殊翻页,到歌曲末尾 */
if(flag == 1)
{
/* 总歌曲数小于4, UP置为1 */
if(songs < 4)
{
*cmd_up = 1;
}
else /* 总歌曲数大于等于4,UP置为歌曲倒数第四首 */
{
(*cmd_up) = (songs - 4 + 1);
}
(*cmd_down) = songs;
}
else if(*current < *cmd_up) /* 当前歌曲光标超过 Up时, 当前显示列表向上移动 */
{
if(*cmd_up == 1)
{
(*cmd_up) = songs;
}
else
{
(*cmd_up)--;
}
if(*cmd_down == 1)
{
(*cmd_down) = songs;
}
else
{
(*cmd_down)--;
}
}
return 0;
}
int cmd_down(int *current, int* cmd_down, int* cmd_up, int songs)
{
int flag = 0;
if(*current == songs)
{
(*current) = 1;
flag = 1;
}
else
{
(*current)++;
}
if(flag == 1)
{
if(songs < 4)
{
*cmd_down = songs;
}
else
{
*cmd_down = 4;
}
*cmd_up = 1;
}
else if(*current > *cmd_down)
{
if(*cmd_down == songs)
{
(*cmd_down) = 1;
}
else
{
(*cmd_down)++;
}
if(*cmd_up == songs)
{
(*cmd_up) = 1;
}
else
{
(*cmd_up)++;
}
}
return 0;
}
int main()
{
int songs;
char cmd[101] = {0};
if(scanf("%d", &songs) != EOF)
{
int up = 1;
int down = 4;
int current = 1;
scanf("%s", cmd);
for(int i = 0; i < strlen(cmd); i++)
{
if(cmd[i] == 'U')
{
/* UP上一首 */
cmd_up(¤t, &up, &down, songs);
}
else if(cmd[i] == 'D')
{
/* DOWN下一首 */
cmd_down(¤t, &down, &up, songs);
}
// printf("up = %d, down = %d, current = %d \n", up, down, current);
}
for(int i = 0; i < 4 && i < songs; i++)
{
if(up > songs)
{
up = 1;
printf("%d ", up++);
}
else
{
printf("%d ", up++);
}
}
printf("\n%d", current);
}
return 0;
}