|
|
вернуться в форумThe subdirectories shall be listed in lexicographic order Can you please say what exactly you mean by "lexicographic order"? As i can see from neerc.ifmo.ru tests, standart C# comparison doesn't fit; and real used order is not so obvious. So i should know what to implement. Why NTFS_W98 comes after NTFSDOS? Why ~INTRO comes after CONTENT? PS: I think that my code is shortest :p -- using System; using System.Collections.Generic; namespace Task1067 { class Directory { private Dictionary<string, Directory> SubDirs; public Directory() { this.SubDirs = new Dictionary<string, Directory>(); } public void ProcessSubdirs(Action<KeyValuePair<string, Directory>> Processor) { List<string> Keys = new List<string>(this.SubDirs.Keys); Keys.Sort(); foreach(string Key in Keys) { Processor(new KeyValuePair<string, Directory>(Key, this.SubDirs[Key])); } } public void AddDir(Stack<string> DirectoryNames) { string Name = DirectoryNames.Pop(); if(!this.SubDirs.ContainsKey(Name)) this.SubDirs[Name] = new Directory(); if(DirectoryNames.Count > 0) this.SubDirs[Name].AddDir(DirectoryNames); } } class Program { private static void PrintSubdirs(Directory Dir, int Depth) { Dir.ProcessSubdirs(delegate(KeyValuePair<string, Directory> kvp) { Console.WriteLine(new String(' ', Depth) + kvp.Key); PrintSubdirs(kvp.Value, Depth+1); }); }
static void Main(string[] args) { int Count = int.Parse(Console.ReadLine()); Directory RootDir = new Directory(); for(int i=0; i<Count; i++) { List<string> PathComponents = new List<string>(Console.ReadLine().Trim().Split('\\')); PathComponents.Reverse(); RootDir.AddDir(new Stack<string>(PathComponents)); } PrintSubdirs(RootDir, 0); } } } Re: The subdirectories shall be listed in lexicographic order ^^ |
|
|