Doorman

2020年1月17日 1017点热度 0人点赞 0条评论

Doorman

时间: 1ms        内存:128M

描述:

The doorman Bruno at the popular night club Heaven is having a hard time fulfilling his duties. He was told by the owner that when the club is full, the number of women and men let into the club should be roughly the same. When the night club opens, people wanting to enter the club are already lined up in a queue, and Bruno can only let them in one-by-one. He lets them in more-or-less in the order they are lined up. He can however decide to let the second person in the queue cut the line and slip into the club before the person in front. This will no doubt upset the person first in line, especially when this happens multiple times,but Bruno is quite a big guy and is capable of handling troublemakers. Unfortunately though, he is not that strong on mental calculations under these circumstances.He finds keeping track of the difference of the number of women and number of men let into the club a challenging task. As soon as the absolute difference gets too big, he looses track of his counting and must declare to the party people remaining in the queue that the club is full.

输入:

The first line of input contains a positive integer X< 100 describing the largest absolute difference between the number of women and number of men let into the club, that Bruno can handle. The second line contains a string consisting solely of the characters ’W’ and ’M’ of length at most 100, describing the genders of the people in the queue, in order. The leftmost character of the string is the gender of the person first in line.

输出:

The maximum number of people Bruno can let into the club without loosing track of his counting. You may assume that the club is large enough to hold all the people in the queue.

示例输入:

2
WMMMMWWMMMWWMW

示例输出:

8

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论