题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
// HJ64-2 MP3光标位置.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int n;
while (cin >> n>>s)
{
int pos = 1, head = 1, end = min(n, 4);
for (auto c : s)
{
if (c == 'U')
{
pos--;
if (pos < 1)
{
pos = n;
end = pos;
head = max(1, n - 4+1);
}
else
{
if (pos < head)
{
head = pos;
end--;
}
}
}
else
{
pos++;
if (pos > n)
{
head = 1;
pos = 1;
end = min(n, 4);
}
else
{
if (pos > end)
{
end = pos;
head++;
}
}
}
}
for (int i = head; i <= end; i++)
{
cout << i << " ";
}
cout << endl;
cout << pos << endl;
}
return 0;
}
查看6道真题和解析