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.
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:
Se l’utente inserisce pwd – il programma dovrebbe stampare la directory di lavoro corrente.
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