Advertisement
Niicksana

04. Files

Jun 25th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _04._Files
  7. {
  8. class Files
  9. {
  10. static void Main(string[] args)
  11. {
  12. // Programming Fundamentals Retake Exam - 11 September 2016
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. Dictionary<string, Dictionary<string, long>> dict = new Dictionary<string, Dictionary<string, long>>();
  16. for (int i = 0; i < n; i++)
  17. {
  18. string line = Console.ReadLine();
  19. string[] lineTokens = line.Split('\\');
  20.  
  21. string root = lineTokens[0].Trim();
  22. string file = lineTokens[lineTokens.Length - 1].Trim();
  23. string[] splitted = file.Split(';');
  24. string fileName = splitted[0].Trim();
  25. long fileSize = long.Parse(splitted[1]);
  26.  
  27. if (!dict.ContainsKey(root))
  28. {
  29. dict.Add(root, new Dictionary<string, long>());
  30. }
  31.  
  32. if (!dict[root].ContainsKey(fileName))
  33. {
  34. dict[root].Add(fileName, fileSize);
  35. }
  36. else
  37. {
  38. dict[root][fileName] = fileSize;
  39. }
  40.  
  41. }
  42.  
  43. string[] find = Console.ReadLine().Split();
  44.  
  45. string searchedRoot = find[2];
  46. string searchedEx = find[0];
  47.  
  48. if (dict.ContainsKey(searchedRoot))
  49. {
  50. Dictionary<string, long> result = dict[searchedRoot];
  51.  
  52. if (result.Count == 0)
  53. {
  54. Console.WriteLine("No");
  55. return;
  56. }
  57. foreach (var kvp in result.OrderByDescending(kvp => kvp.Value).ThenBy(kvp => kvp.Key))
  58. {
  59. if (kvp.Key.EndsWith(searchedEx))
  60. {
  61. Console.WriteLine($"{kvp.Key} - {kvp.Value} KB");
  62. }
  63. }
  64. }
  65. else
  66. {
  67. Console.WriteLine("No");
  68. }
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement