山折り谷折り〜 横へな 2014.2.1 参考問題

問題

紙を何度か折ってから広げると、山折りと谷折の跡がつく。
山折りと谷折りがどんな順序でできるのかを計算せよ。

紙の折り方は、以下の5種類。

記号 折り方
L 縦に二つ折り。右側を固定。中央を谷折り。
J 縦に二つ折り。左側を固定。中央を谷折り。
Z 縦に三つ折り。右側を固定。右側は谷折り、左側は山折り。
U 縦に三つ折り。中央を固定。右も左も谷折り。
S 縦に三つ折り。左側を固定。右側は山折り、左側は谷折り。

例えば。
JZ と折ると、

という具合になる。これを開くと

こんな具合になるので、折り目は左から順に
山, 谷, 谷, 山, 谷
となる。

入力と出力

入力は JZ こんな感じ。折り方の記号を、折る順序のとおりに区切り文字なしで並べたもの。
J L Z U S のいずれかの文字のみで構成される。

出力は mVVmV こんな感じ。
山折りを m , 谷折りを V で表現し、折り目の向きを左から順に記載する。
こちらも区切り文字はない。

補足

サンプルデータ

# 入力 期待
0 JZ mVVmV
1 J V
2 L V
3 Z mV
4 U VV
5 S Vm
6 JL VVm
7 JS VmVVm
8 JU VVVmm
9 LU mmVVV
10 SL VVmmV
11 SS VmVVmmVm
12 SU VVVmmmVV
13 SZ mVVmVmmV
14 UL mVVVm
15 UU mmVVVVmm
16 UZ mVVmVVmV
17 ZJ VmmVV
18 ZS VmmVmVVm
19 ZZ mVmmVVmV
20 JJJ VVmVVmm
21 JJZ mVVmVVmVmmV
22 JSJ VVmmVVmVVmm
23 JSS VmVVmmVmVVmVVmmVm
24 JUS VmVVmVVmVVmmVmmVm
25 JUU mmVVVVmmVVVmmmmVV
26 JUZ mVVmVVmVVmVmmVmmV
27 LJJ VmmVVVm
28 LLS VmmVmVVmVVm
29 LLU mmmVVVmmVVV
30 LLZ mVmmVVmVVmV
31 LSU mmVVVmmmVVVVmmmVV
32 LSZ mVVmVmmVVmVVmVmmV
33 LZL mmVVmVVmmVV
34 LZS VmmVmVVmVVmmVmVVm
35 LZU mmmVVVmmVVVmmmVVV
36 SJL VVmVVmmmVVm
37 SLU mm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