题解 | #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;
}

全部评论

相关推荐

04-01 16:02
已编辑
武汉工程大学 Java
牛客98843461...:处女面??我还种马面渣男面处男面呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务