Go Straight and Turn Right
500 MS 64 MB | Markdown 公开数据 显示标签
入门 (*800) 模拟
11 | 11 |
通过 | 提交 |
题目描述
Consider an $xy$-plane. The positive direction of the $x$-axis is in the direction of east, and the positive direction of the $y$-axis is in the direction of north.
Takahashi is initially at point $(x,y)=(0,0)$ and facing east (in the positive direction of the $x$-axis).
You are given a string $T=t_1t_2\cdots t_N$ of length $N$ consisting of `S` and `R`. Takahashi will do the following move for each $i=1,2,…,N$ in this order.
- If $t_i$ = `S`, Takahashi advances in the current direction by distance $1$.
- If $t_i$ = `R`, Takahashi turns $90$ degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.
- If he is facing east (in the positive direction of the $x$-axis) before he turns, he will face south (in the negative direction of the $y$-axis) after he turns.
- If he is facing south (in the negative direction of the $y$-axis) before he turns, he will face west (in the negative direction of the $x$-axis) after he turns.
- If he is facing west (in the negative direction of the $x$-axis) before he turns, he will face north (in the positive direction of the $y$-axis) after he turns.
- If he is facing north (in the positive direction of the $y$-axis) before he turns, he will face east (in the positive direction of the $x$-axis) after he turns.
Print the coordinates Takahashi is at after all the steps above have been done.
输入格式
Input is given from Standard Input in the following format:
>$N$\
>$T$
#### Constraints
- $1\le N\le 10^5$
- $N$ is an integer.
- $T$ is a string of length $N$ consisting of `S` and `R`.
输出格式
Print the coordinates $(x,y)$ Takahashi is at after all the steps described in the Problem Statement have been completed, in the following format, with a space in between:
```
x y
```
样例输入 #1
4 SSRS
样例输出 #1
2 -1
样例输入 #2
20 SRSRSSRSSSRSRRRRRSRR
样例输出 #2
0 1
提示
***For Sample #1:***
Takahashi is initially at $(0,0)$ facing east. Then, he moves as follows.
1. $t_1$ = `S`, so he advances in the direction of east by distance $1$, arriving at $(1,0)$.
2. $t_2$ = `S`, so he advances in the direction of east by distance $1$, arriving at $(2,0)$.
3. $t_3$ = `R`, so he turns $90$ degrees clockwise, resulting in facing south.
4. $t_4$ = `S`, so he advances in the direction of south by distance $1$, arriving at $(2,−1)$.
Thus, Takahashi's final position, $(x,y)=(2,−1)$, should be printed.
来源
AtCoder [ABC244B]