オペレーティングシステムの設計

Linuxオペレーティングシステムの生みの親であるLinus Torvaldsは、コードベースのメンテナンスをあなたに任せることを決めました。しかし、あなたは実験好きなので、最もよく使われるコマンドをいくつか書き換えて、それを本番環境に投入してみようと考えています。

Cohen-Linus-Torvalds.webp

今週は、pwd (カレントディレクトリの表示) と cd (ディレクトリの移動) コマンドを書き換えたいと考えています。これらのコマンドはユーザーの入力に基づいて動作するようにしたいと思っています。

  1. ユーザーが pwd と入力した場合 - プログラムは現在の作業ディレクトリを表示する必要があります。

  2. ユーザーが cd folder と入力した場合 - プログラムは指定されたフォルダに移動します。特に以下のケースに対応する必要があります:

    • If the folder is .. - it means that the program should move to the parent directory. So, if we’re at directory /usr/local/bin/, the program should move to /usr/local/.

    • If the folder is . - it means that the program should stay in the current directory.

    • If the folder starts with /, it means that the program should change the absolute path of the directory - not the relative. So, if we’re at directory /usr/local/bin/, and the input was cd /dev, the program should move to /dev/.

    • If the folder is a name (Latin letters or numbers) - the program should move to that directory relative to the current one. So, if we’re at directory /usr/local/bin/, and the input was cd ../lib, the program should move to /usr/local/lib/.

- フォルダが .. の場合 - 親ディレクトリに移動します。たとえば、現在のディレクトリが /usr/local/bin/ のとき、.. に移動すると /usr/local/ に切り替わります。

入力

最初の行に、コマンドの数 n (1 ≤ n ≤ 100) が与えられます。

次に続く n 行にコマンドが与えられ、それぞれ200文字を超えないことが保証されています。

出力

pwd コマンドが実行されるたびに、その結果を1行ごとに出力してください。

Input

Output

5
pwd
cd usr/local/bin
cd ..
pwd
cd /dev

/
/usr/local/

7
pwd
cd /home/anna
pwd
cd ..
pwd
cd anna/../bob
pwd

/
/home/anna/
/home/
/home/bob/

4
cd /usr/local
pwd
cd ../usr/local
pwd

/usr/local/
/usr/usr/local/

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue