Advertisement
Guest User

04.Files

a guest
Jan 3rd, 2017
90
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 _04.Files
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. Dictionary<string, Dictionary<string, decimal>> dict = new Dictionary<string, Dictionary<string, decimal>>();
  15. int n = int.Parse(Console.ReadLine());
  16. for (int i = 0; i < n; i++)
  17. {
  18. string input = Console.ReadLine();
  19. var everything = input.Split('\\').ToList();
  20. string root = everything[0];
  21. var fileAndSize = everything[everything.Count - 1].Split(';').ToList();
  22. string fileName = fileAndSize[0];
  23. decimal fileSize = long.Parse(fileAndSize[1]);
  24. if (!dict.ContainsKey(root))
  25. {
  26. dict.Add(root, new Dictionary<string, decimal>());
  27. dict[root].Add(fileName, fileSize);
  28. }
  29. else
  30. {
  31. if (!dict[root].ContainsKey(fileName))
  32. {
  33. dict[root].Add(fileName, fileSize);
  34. }
  35. else
  36. {
  37. dict[root][fileName] = fileSize;
  38. }
  39. }
  40. }
  41. SortedDictionary<string, decimal> result = new SortedDictionary<string, decimal>();
  42. List<string> end = Console.ReadLine().Split(' ').ToList();
  43. string resultType = "." + end[0];
  44. string resultRoot = end[2];
  45. foreach (KeyValuePair<string, Dictionary<string, decimal>> pair in dict)
  46. {
  47. if (pair.Key == resultRoot)
  48. {
  49. foreach (KeyValuePair<string, decimal> innerpair in dict[pair.Key])
  50. {
  51. if (innerpair.Key.Contains(resultType))
  52. {
  53. result.Add(innerpair.Key, innerpair.Value);
  54. }
  55. }
  56. }
  57. }
  58. if (result.Count == 0)
  59. {
  60. Console.WriteLine("No");
  61. }
  62. else
  63. {
  64. foreach (KeyValuePair<string, decimal> pair in result.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  65. {
  66. Console.WriteLine($"{pair.Key} - {pair.Value} KB");
  67. }
  68.  
  69. }
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement