Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _4.Files
  7. {
  8. public class Files
  9. {
  10. public static void Main()
  11. {
  12. var dictionary = new Dictionary<string, Dictionary<string, long>>();
  13.  
  14. var n = int.Parse(Console.ReadLine());
  15.  
  16. for (int i = 0; i < n; i++)
  17. {
  18. var currentFileData = Console.ReadLine().Split('\\');
  19.  
  20. var fileRoot = currentFileData[0];
  21.  
  22. var fileNameExtensionAndSize = currentFileData[currentFileData.Length - 1].Split(';');
  23. var fileNameAndExtension = fileNameExtensionAndSize[0];
  24. var fileSize = long.Parse(fileNameExtensionAndSize[1]);
  25.  
  26. if ( !dictionary.ContainsKey(fileRoot) )
  27. {
  28. dictionary[fileRoot] = new Dictionary<string, long>();
  29. }
  30.  
  31. dictionary[fileRoot][fileNameAndExtension] = fileSize;
  32. }
  33.  
  34. var filesToSearch = Console.ReadLine().Split().ToList();
  35. var extension = filesToSearch[0];
  36. var root = filesToSearch[2];
  37.  
  38. if ( !dictionary.ContainsKey(root) )
  39. {
  40. Console.WriteLine("No");
  41. Environment.Exit(1);
  42. }
  43.  
  44. var resultDictionary = dictionary[root]
  45. .Where(x => x.Key.EndsWith(extension))
  46. .OrderByDescending(x => x.Value)
  47. .ThenBy(x => x.Key)
  48. .ToDictionary(x => x.Key, y => y.Value); ;
  49.  
  50. if ( resultDictionary.Count == 0 )
  51. {
  52. Console.WriteLine("No");
  53. Environment.Exit(1);
  54. }
  55.  
  56. foreach ( var file in resultDictionary )
  57. {
  58. Console.WriteLine($"{file.Key} - {file.Value} KB");
  59. }
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement