Advertisement
North_Point

04. Files

Aug 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 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.             var n = int.Parse(Console.ReadLine());
  14.             var dic = new Dictionary<string, Dictionary<string, long>>();
  15.  
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 var tokens = Console.ReadLine().Split('\\');
  19.                 var data = tokens.Last().Split(';');
  20.                 var fileName = data[0];
  21.                 var fileSize = long.Parse(data.Last());
  22.                
  23.  
  24.                 if (!dic.ContainsKey(tokens[0]))
  25.                 {
  26.                     dic.Add(tokens[0], new Dictionary<string, long>());
  27.                 }
  28.                 if (!dic[tokens[0]].ContainsKey(fileName))
  29.                 {
  30.                     dic[tokens[0]].Add(fileName, fileSize);
  31.                 }
  32.                 else
  33.                 {
  34.                     dic[tokens[0]][fileName] = fileSize;
  35.                 }
  36.  
  37.             }
  38.             var contain = Console.ReadLine().Split(new string[] { " in "},StringSplitOptions.RemoveEmptyEntries);
  39.             var file = contain[0];
  40.             var folder = contain[1];
  41.  
  42.             if (dic.ContainsKey(folder))
  43.             {
  44.                 Dictionary<string, long> foundFiles = dic[folder];
  45.                 foreach (var item in foundFiles.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  46.                 {
  47.                     if (item.Key.EndsWith(file))
  48.                     {
  49.                         Console.WriteLine("{0} - {1} KB",item.Key,item.Value);
  50.                     }
  51.                 }
  52.             }
  53.             else
  54.             {
  55.                 Console.WriteLine("No");
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement