#K47232. Normalize Unix File Path
Normalize Unix File Path
Normalize Unix File Path
In this problem, you are given a Unix-like file path which may contain redundant slashes ('/') and special directory indicators '.' (current directory) and '..' (parent directory). Your task is to simplify the path and convert it into its canonical form.
The normalization rules are as follows:
- Any multiple consecutive slashes should be replaced by a single slash.
- Any occurrence of the current directory, denoted as '.' , should be removed.
- The parent directory indicator '..' moves one directory up unless it is already at the root directory.
Formally, given an input string representing a file path, you need to compute its normalized form. For example, if the input is "/home//foo/", the normalized path is "/home/foo". In LaTeX, the example can be expressed as:
$$\texttt{/home//foo/} \rightarrow \texttt{/home/foo} $$Your solution should read the input from standard input (stdin) and print the result to standard output (stdout).
inputFormat
The input consists of a single line containing a string which is the Unix-style file path. The path always starts with a '/' and consists of English letters, digits, '.', '/', and '_' characters.
outputFormat
Output the normalized canonical path as a single line string to standard output (stdout).## sample
/home//foo/
/home/foo
</p>