問題一覧 > 通常問題

No.1806 Rotating Golem

レベル : / AI推定難易度 : 96 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 272
作問者 : MasKoaTS / テスター : ygussany Shirotsume
お気に入りにしたユーザー ProblemId : 7475 / 自分の提出
問題文最終更新日: 2024-11-28 18:31:14
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 327 (順位表) の他の問題:

Problem Statement

The wizard Koa has summoned a golem.

The golem initially faces one of the directions "East", "West", "South", or "North",
and each time Koa gives $1$ command, the direction the golem faces rotates $90$ degrees to the right.

That is, if the golem was facing north, it changes to east; if east, to south; if south, to west; and if west, to north.

You are given characters $A$, $B$ representing directions.
Each of them is $1$ character, one of E, W, S, N, corresponding to "East", "West", "South", and "North", respectively.

When Koa gives $0$ or more commands to change the direction the golem faces from $A$ to $B$,
what is the minimum number of commands required?

Constraints

  • $A$, $B$ are each $1$ character, one of E, W, S, N

Input

The input is given in the following format.

$A$
$B$
  • Line $1$ contains $A$

  • Line $2$ contains $B$

Output

Print the answer on $1$ line, followed by a newline.

Sample

Sample 1
Input
E
N
Output
3

If $3$ commands are given, the golem's direction changes as follows.

  • Command $1$ : East → South

  • Command $2$ : South → West

  • Command $3$ : West → North

Therefore, the answer is $3$.

Sample 2
Input
S
S
Output
0

The golem is facing south from the start, so no commands need to be given.

Sample 3
Input
W
E
Output
2

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。