Advertisement
Guest User

04.Files

a guest
Sep 13th, 2016
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. namespace _00.Test
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class TestMain
  8. {
  9.  
  10. public static void Main(string[] args)
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13.  
  14. Dictionary<string, List<string>> rootByFileNames = new Dictionary<string, List<string>>();
  15. Dictionary<string, long> fileBySize = new Dictionary<string, long>();
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. string inputLine = Console.ReadLine();
  20.  
  21. string[] fileArgs = inputLine.Split('\\');
  22. string rootName = fileArgs[0];
  23.  
  24. string[] fileInfo = fileArgs[fileArgs.Length - 1].Split(';');
  25.  
  26. string fileNameAndExtension = fileInfo[0];
  27. long fileSize = long.Parse(fileInfo[1]);
  28.  
  29. if (!rootByFileNames.ContainsKey(rootName))
  30. {
  31. rootByFileNames.Add(rootName, new List<string>());
  32. }
  33.  
  34. rootByFileNames[rootName].Add(fileNameAndExtension);
  35. fileBySize[fileNameAndExtension] = fileSize;
  36. }
  37.  
  38. string[] searchedFileArgs = Console.ReadLine().Split(' ');
  39. string extension = searchedFileArgs[0].Trim();
  40. string searchedRootName = searchedFileArgs[2].Trim();
  41.  
  42. fileBySize = fileBySize.OrderByDescending(f => f.Value).ToDictionary(p => p.Key, p => p.Value);
  43. if (rootByFileNames.ContainsKey(searchedRootName))
  44. {
  45. List<string> allfiles = rootByFileNames[searchedRootName].Where(f => f.EndsWith(extension)).ToList();
  46. if (allfiles.Count == 0)
  47. {
  48. Console.WriteLine("No");
  49. }
  50. else
  51. {
  52. foreach (var item in fileBySize.Where(f => allfiles.Contains(f.Key)).OrderByDescending(f => f.Value).ThenBy(f => f.Key))
  53. {
  54. Console.WriteLine($"{item.Key} - {item.Value} KB");
  55. }
  56. }
  57. }
  58. else
  59. {
  60. Console.WriteLine("No");
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement