meghana180799

Untitled

Jul 9th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. Zack is learning Operating Systems. He came across the following commands:
  2. cd - changes the location of working directory, and
  3. pwd - display the present working directory
  4.  
  5. If the cd parameter contains "..", that means you have to step back one directory. The path of directories is separated by slashes "/". The default root directory is "/". Your task is to print the current working directory, for each "pwd" command.
  6.  
  7. Input Format
  8.  
  9. First line of input contains T - number of test cases. For each test case, first line of input contains N - number of commands. Its followed by N lines, each containing either a "cd <path>" or a "pwd" command. Each "cd" command will end with a "/".
  10.  
  11. Constraints
  12.  
  13. 1 <= T <= 100
  14. 1 <= N <= 100
  15. 1 <= len(path) <= 200
  16. path[i] ∈ ('a' - 'z', '.', '/')
  17.  
  18. Output Format
  19.  
  20. For each "pwd" command, print the present working directory, separated by new line. Print newline between output of test cases.
  21.  
  22. Sample Input 0
  23.  
  24. 2
  25. 8
  26. pwd
  27. cd /Users/Guest/
  28. pwd
  29. cd ../Admin/Desktop/
  30. pwd
  31. cd /Users/Guest/Desktop/
  32. cd os/labs/
  33. pwd
  34. 6
  35. cd /sem/networks/labs/
  36. pwd
  37. cd ../../os/labs/../slides/
  38. pwd
  39. cd /
  40. pwd
  41.  
  42.  
  43. Sample Output 0
  44. /
  45. /Users/Guest/
  46. /Users/Admin/Desktop/
  47. /Users/Guest/Desktop/os/labs/
  48.  
  49. /sem/networks/labs/
  50. /sem/os/slides/
  51. /
Add Comment
Please, Sign In to add comment