Օպերացիոն համակարգի նախագծում

Linus Torvalds-ը (Linux օպերացիոն համակարգի հիմնադիրը) ձեզ է վստահել համակարգի ծածկագիրն սպասարկելու պարտականությունը: Բայց քանի որ սիրում եք նորարարություններ, որոշել եք փոփոխել ու նորից գրել ամենահայտնի հրամաններից մի քանիսը և տեղակայել դրանք production միջավայրում։
notion image
Այս շաբաթ վերաշարադրում եք pwd (print working directory) և cd (change directory) հրամանները։ Ցանկանում եք, որ դրանք գործեն օգտատիրոջ մուտքագրած հրամանների հիման վրա.
  1. Երբ օգտատերը ներմուծում է pwd, ծրագիրը պետք է տպի գործող (ընթացիկ) թղթապանակը:
  1. Երբ օգտատերը ներմուծում է 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 են, և յուրաքանչյուր արդյունք պետք է տպվի նոր տողի վրա։

Օրինակներ

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