Progettare un sistema operativo

Linus Torvalds, il creatore del sistema operativo Linux, ha deciso di affidarti la manutenzione del codice del sistema operativo. Tuttavia, dal momento che ami sperimentare, hai deciso di riscrivere alcuni tra i comandi più utilizzati e distribuire queste modifiche in produzione.
notion image
Questa settimana ti dedicherai alla riscrittura dei comandi pwd (print working directory) e cd (change directory). Desideri che tali comandi funzionino in base all’input dell’utente:
  1. Se l’utente inserisce pwd – il programma dovrebbe stampare la directory di lavoro corrente.
  1. Se l’utente inserisce cd folder – il programma dovrebbe spostarsi nella cartella specificata:
      • 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/.
- Se la cartella è .. – significa che il programma si sposta nella directory padre. Ad esempio, se ci troviamo nella directory /usr/local/bin/, il programma dovrebbe passare a /usr/local/.

Input

La prima riga dell’input contiene un singolo intero n (1 ≤ n ≤ 100), che rappresenta il numero di comandi.
Le successive n righe contengono i comandi. È garantito che la lunghezza di ciascun comando non superi i 200 caratteri.

Output

Il programma deve stampare i risultati di tutti i comandi pwd, ognuno su una riga separata.

Esempi

Ingresso
Uscita
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