题解 | #MP3光标位置#

MP3光标位置

http://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15

while True:
	try:
		n = int(input())
		s = input()
		play_list = [i for i in range(1, n+1)]
		if n <= 4:
			top = 0
			bottom = top + n - 1
			this = top
			for c in s:
				if c == 'U':
					if this > 0:
						this -= 1
					else:
						this = n - 1
				elif c == 'D':
					if this < n - 1:
						this += 1
					else:
						this = 0
			print(' '.join([str(i) for i in play_list]))
			print(play_list[this])
		else:
			top = 0
			bottom = top + 3
			this = top
			shift = 0
			for c in s:
				if c == 'U':
					if shift > 0:
						shift -= 1
						this -= 1
					else:
						if top - 1 >= 0:
							shift = 0
							top -= 1
							bottom = top + 3
							this -= 1
						else:
							bottom = n - 1
							top = bottom - 3
							this = bottom
							shift = 3
				elif c == 'D':
					if shift < 3:
						shift += 1
						this += 1
					else:
						if bottom + 1 < n:
							bottom += 1
							top = bottom - 3
							this += 1
							shift = 3
						else:
							top = 0
							bottom = top + 3
							this = 0
							shift = 0
			print(' '.join([str(i) for i in play_list[top:bottom+1]]))
			print(play_list[this])
	except:
		break
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 15:36
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
Yki_:你要算时间成本呀,研究生两三年,博士三四年,加起来就五六年了,如果你本科去腾讯干五年,多领五年的年薪,加上公司内涨薪,可能到时候十五年总薪资也跟博士差不多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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