Gestaltung eines Betriebssystems

Linus Torvalds, der Entwickler des Linux-Betriebssystems, hat Ihnen das Vertrauen geschenkt, den Code dieses Systems zu warten. Da Sie gerne experimentieren, haben Sie jedoch beschlossen, einige der populärsten Befehle neu zu schreiben und sie direkt in der Produktion einzusetzen.
notion image
In dieser Woche schreiben Sie die Befehle pwd (print working directory) und cd (change directory) neu. Sie möchten, dass diese Befehle entsprechend der Eingabe des Benutzers funktionieren:
  1. Wenn der Benutzer pwd eingibt, soll das Programm das aktuelle Arbeitsverzeichnis ausgeben.
  1. Wenn der Benutzer cd folder eingibt, soll das Programm in diesen Ordner wechseln:
      • 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/.
- Ist der Ordner .., bedeutet dies, dass das Programm ins übergeordnete Verzeichnis wechselt. Befindet man sich zum Beispiel im Verzeichnis /usr/local/bin/, soll das Programm nach /usr/local/ wechseln.

Eingabe

Die erste Zeile der Eingabe enthält eine einzelne ganze Zahl n (1 ≤ n ≤ 100), die die Anzahl der Befehle angibt.
Die nächsten n Zeilen enthalten die Befehle. Es ist garantiert, dass die Länge jedes Befehls 200 Zeichen nicht überschreitet.

Ausgabe

Das Programm soll die Ergebnisse aller pwd-Befehle jeweils in einer eigenen Zeile ausgeben.

Beispiele

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