using System.Collections.Generic;
public static string GetShortPath(string path) {
var res = new StringBuilder();
string[] blocks = path.Trim('/').Split('/');
var dirs = new Stack<string>();
foreach (string s in blocks)
if (s.Length == 0 || s == ".")
var reverse = new Stack<string>();
reverse.Push(dirs.Pop());
res.Append(reverse.Pop());
public static void Main()
Console.WriteLine("UniLecs");
Console.WriteLine(GetShortPath("/home/"));
Console.WriteLine(GetShortPath("/../"));
Console.WriteLine(GetShortPath("/a/./b/../../c/"));