JC15B - Folding Stick
Today Satria really excited about fractals (recurrence pattern), the first fractal type he learn is the dragon curve fractal. To make the dragon curve, it can be easily simulated by folding the paper and open it 90 degrees (parellel to X axis or Y axis) like this image below:
Satria realized that the can be many ways to fold the paper, so he make an experiment. Initially there is a stick length 2N, he then place the stick parallel to x axis with one end lies on coordinate (0,0) and the other end lies on coordinate (2N,0). He then fold the stick, so the new folded stick occupy (0,0) to (2N-1,0) he keep doing that until the final folded stick occupy (0,0) to (1,0). In each foding there are two types of folding, folding UP (via possitive Y coordinate) and folding down (via negative Y coordinate). he then open all the folding with angle 90 degrees so each stick segment will be parallel ot X axis or Y axis. Now he wonder if he open all the folding with angle 90 degrees, what is the coordinate of the other end of that stick. Can you help him?
The first line there is an integer N denoting number of folding and a string S the sequence of folding and the type of folding.
You sould output two integers x and y which is the coordinate of the other end of that stick.
1 ≤ N ≤ 50
Length of string S is equal to N, in other word: |S|=N.
String S containing two possible characters:
- 'U' means folding UP (positive Y direction)
- 'D' means folding DOWN (negative Y direction)
Sample 3 Explanation
Here is the image illustrating sample 3 on how the stick is folded and openned with 90 degrees angle.
As seen in the picture above the other end of the stick after folding and openning lies on coordinate (2,0).
Sample 5 explanation
Here is the final openned stick on test case 5, the other end of the stick after folding and openning lies on coordinate (-2,2)