1870. Cards

单点时限: 2.0 sec

内存限制: 256 MB

You are playing a game with a deck of cards, half red and half black. After your friend thoroughly shuffles the cards, you cut the deck. Your friend then begins to turn the cards over one at a time, starting from the top of the deck. If, at any time, there are more red cards showing than black cards, you lose. If this never occurs by they time all the cards have been turned up, you win.

After losing several times in a row, you get frustrated and decide to cheat. After your friend shuffles the deck, you distract him and then secretly look at the cards, to figure out where you should cut the deck.

“Cutting the deck” means to take a stack of cards off the top of the deck, and place this stack on the bottom.

输入格式

There are many tests.Each test given a deck,the length of deck at most 100000, representing the cards, A ‘R’ indicates a red card, and a ‘B’ indicates a black card. The first character of deck represents the top card, and the last character represents the bottom card.

输出格式

Output the number of cards you should remove from the top of the deck when you cut. If there are multiple possibilities, return the smallest number.

样例

Input
BRBRBR
RBRBRB
Output
0
1
Hint:
case 1:You could cut the deck at positions 0, 2, or 4 to win.
case 2:If you cut the deck at position 0, the first card dealt will be red and you will lose immediately. However, if you cut the deck at position 1, you will win.

18 人解决,44 人已尝试。

19 份提交通过,共有 124 份提交。

6.6 EMB 奖励。

创建: 16 年前.

修改: 6 年,7 月前.

最后提交: 6 年,1 月前.

来源: N/A

题目标签