Advertisement
Guest User

zadacha4

a guest
Oct 20th, 2016
280
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication15
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var finalInfos = new SortedDictionary<string, Dictionary<string, Dictionary<string, Dictionary<long, string>>>>();
  15. //directory -> filename -> fileend -> filesize
  16. var final = new Dictionary<string, long>();
  17. int n = int.Parse(Console.ReadLine());
  18. for (int i = 0; i < n; i++)
  19. {
  20. string read = Console.ReadLine();
  21. string[] info = read.Split('\\',';').ToArray();
  22. string directory = info[0];
  23. long size = Int64.Parse(info[info.Length - 1]);
  24. string filenamee = info[info.Length - 2];
  25. string pattern = @".([^.\\]+)$";
  26. string filename = Regex.Replace(filenamee, pattern, "");
  27. string fileend = filenamee.Replace(filename, "");
  28. string finalInfo = directory + "\\" + filename + fileend;
  29. finalInfos[finalInfo] = new Dictionary<string, Dictionary<string, Dictionary<long, string>>>();
  30. finalInfos[finalInfo][filename] = new Dictionary<string, Dictionary<long, string>>();
  31. finalInfos[finalInfo][filename][fileend] = new Dictionary<long, string>();
  32. finalInfos[finalInfo][filename][fileend][size] = directory;
  33. }
  34. string function = Console.ReadLine();
  35. string[] funcInfo = function.Split(' ').ToArray();
  36. string ende = funcInfo[0];
  37. string end = "." + ende;
  38. string dir = funcInfo[2];
  39. foreach (var dvoika in finalInfos)
  40. {
  41. foreach (var pair in dvoika.Value)
  42. {
  43. foreach (var item in pair.Value.Where(w => w.Key == end))
  44. {
  45. foreach (var thing in item.Value.Where(x => x.Value == dir).OrderByDescending(y => y.Key))
  46. {
  47. string lastanme = pair.Key + item.Key;
  48. final[lastanme] = thing.Key;
  49. }
  50. }
  51. }
  52. }
  53. if (final.Count == 0)
  54. {
  55. Console.WriteLine("No");
  56. }
  57. else
  58. {
  59. foreach (var pair in final.OrderByDescending(w => w.Value))
  60. {
  61. Console.WriteLine($"{pair.Key} - {pair.Value} KB");
  62. }
  63. }
  64. }
  65. }
  66. }
Advertisement
RAW Paste Data Copied
Advertisement