No.104 National Routes
タグ : / 解いたユーザー数 770
作問者 :
nmnmnmnmnmnmnm
Problem Statement
The country of Yukikoda has national routes numbered starting from 1.
So that national routes can be told apart, no two national routes have the same number.
First, National Route 1 starts from Yukikoda Castle.
Every national route eventually branches into a left road and a right road.
National routes branch starting from the smaller-numbered national routes, using the smallest numbers available.
When branching, the left national route always has a smaller number than the right national route.
Route 1 branches into Route 2 on the left and Route 3 on the right.
Route 2 branches into Route 4 on the left and Route 5 on the right.
Route 3 branches into Route 6 on the left and Route 7 on the right.
Route 4 branches into Route 8 on the left and Route 9 on the right.
Route 5 branches into Route 10 on the left and Route 11 on the right.
National routes are numbered according to these rules.
Now, A-kun has left Yukikoda Castle and passed through some branch points without ever turning back.
A-kun remembers, in order, whether he took the left or the right at each branch.
Determine which route A-kun is currently walking on.
Input
S
A string S representing the directions taken at the branches is given.
S is a string of at least 0 and at most 30 characters consisting of the characters 'L' and 'R'.
'L' means moving left at a branch point, and 'R' means moving right.
The beginning of the string is A-kun's oldest memory, and the memories become newer in order.
A newline is always present at the end, so it is never the case that nothing at all is given, even for a string of 0 characters.
Output
Output on one line the number of the national route A-kun is walking on.
Do not forget the newline.
Sample
Sample 1
Input
LR
Output
5
A-kun is initially walking on Route 1.
At the first branch point, Route 1 branches into Route 2 on the left and Route 3 on the right.
A-kun walks on Route 2 on the left.
At the second branch point, Route 2 branches into Route 4 on the left and Route 5 on the right.
A-kun walks on Route 5 on the right.
So A-kun is currently walking on Route 5.
Sample 2
Input
RLL
Output
12
A-kun is initially walking on Route 1.
At the first branch point, Route 1 branches into Route 2 on the left and Route 3 on the right.
A-kun walks on Route 3 on the right.
At the second branch point, Route 3 branches into Route 6 on the left and Route 7 on the right.
A-kun walks on Route 6 on the left.
At the third branch point, Route 6 branches into Route 12 on the left and Route 13 on the right.
A-kun walks on Route 12 on the left.
So A-kun is currently walking on Route 12.
Sample 3
Input
RLLRLRLRRRLRL
Output
12986
Sample 4
Input
Output
1
A-kun has no memory of branching. Therefore, he is walking on Route 1.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。