Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Files
  8. {
  9. class Program
  10. {
  11. private static void AddRoots(List<Root> roots)
  12. {
  13. string[] input = Console.ReadLine().Split(new char[] { '\\', ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  14. string directoryName = input[0];
  15. string fileName = input[input.Length - 2];
  16. long fileSize = long.Parse(input.Last());
  17. foreach (var root in roots)
  18. {
  19. if (root.Name == directoryName)
  20. {
  21. if (root.Files.Keys.Contains(fileName))
  22. {
  23. root.Files[fileName] = fileSize;
  24. return;
  25. }
  26. else
  27. {
  28. root.Files.Add(fileName, fileSize);
  29. return;
  30. }
  31. }
  32. }
  33. roots.Add(new Files.Root
  34. {
  35. Name = directoryName,
  36. Files = new Dictionary<string, long>()
  37. {
  38. { fileName, fileSize }
  39. }
  40. });
  41. }
  42.  
  43. private static void PrintFiles(List<Root> roots, string[] searchFor)
  44. {
  45. string rootName = searchFor[1];
  46. string fileName = searchFor[0];
  47. bool isEmpty = true;
  48. foreach (var root in roots.Where(x => x.Name == rootName))
  49. {
  50. foreach (var file in root.Files.Where(x => x.Key.Contains(fileName)).OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  51. {
  52. Console.WriteLine("{0} - {1} KB", file.Key, file.Value);
  53. isEmpty = false;
  54. }
  55. }
  56. if (isEmpty)
  57. {
  58. Console.WriteLine("No");
  59. }
  60. }
  61.  
  62. static void Main(string[] args)
  63. {
  64. int rootNums = int.Parse(Console.ReadLine());
  65. List<Root> roots = new List<Root>();
  66. for (int i = 0; i < rootNums; i++)
  67. {
  68. AddRoots(roots);
  69.  
  70. }
  71. string[] searchFor = Console.ReadLine().Split(new string[] { " in " }, StringSplitOptions.None).ToArray();
  72. PrintFiles(roots, searchFor);
  73. }
  74. }
  75.  
  76. class Root
  77. {
  78. public string Name { get; set; }
  79. public Dictionary<string, long> Files { get; set; }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement