Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Files
  9. {
  10. class Program
  11. {
  12. private static void AddRoots(List<Root> roots)
  13. {
  14. string[] input = Console.ReadLine().Split(new char[] { '\\', ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  15. string directoryName = input[0];
  16. string fileName = input[input.Length - 2];
  17. long fileSize = long.Parse(input.Last());
  18. foreach (var root in roots)
  19. {
  20. if (root.Name == directoryName)
  21. {
  22. if (root.Files.Keys.Contains(fileName))
  23. {
  24. root.Files[fileName] = fileSize;
  25. return;
  26. }
  27. root.Files.Add(fileName, fileSize);
  28. return;
  29. }
  30. }
  31. roots.Add(new Files.Root
  32. {
  33. Name = directoryName,
  34. Files = new Dictionary<string, long>()
  35. {
  36. { fileName, fileSize }
  37. }
  38. });
  39. }
  40.  
  41. private static void PrintFiles(List<Root> roots, string[] searchFor)
  42. {
  43. string rootName = searchFor[1].Trim();
  44. string fileName = searchFor[0].Trim();
  45. bool isEmpty = true;
  46. foreach (var root in roots.Where(x => x.Name == rootName))
  47. {
  48. foreach (var file in root.Files.Where(x => Path.GetExtension(x.Key).Contains(fileName))
  49. .OrderByDescending(x => x.Value)
  50. .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.RemoveEmptyEntries).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