Advertisement
Guest User

filez

a guest
Jan 3rd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Files
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var n = int.Parse(Console.ReadLine());
  12.             var files = new Dictionary<string, Dictionary<string, Dictionary<string, decimal>>>();
  13.             while (n-- > 0)
  14.             {
  15.                 var tokens = Console.ReadLine().Split(';');
  16.                 var fileSize = decimal.Parse(tokens[1]);
  17.                 var path = tokens[0].Split('\\');
  18.                 var fileRoot = path[0];
  19.                 var fileName = path[path.Length - 1];
  20.                 var fileExtension = fileName.Split('.').Last();
  21.                 if (!files.ContainsKey(fileRoot))
  22.                 {
  23.                     files[fileRoot] = new Dictionary<string, Dictionary<string, decimal>>();
  24.                     files[fileRoot][fileExtension] = new Dictionary<string, decimal>();
  25.                 }
  26.  
  27.                 if (!files[fileRoot].ContainsKey(fileExtension))
  28.                 {
  29.                     files[fileRoot][fileExtension] = new Dictionary<string, decimal>();
  30.                 }
  31.  
  32.                 files[fileRoot][fileExtension][fileName] = fileSize;
  33.             }
  34.             var last = Console.ReadLine().Split(' ');
  35.             var extension = last.First();
  36.             var root = last.Last();
  37.  
  38.             try
  39.             {
  40.                 foreach (var nameSizePair in files[root][extension]
  41.                     .OrderByDescending(f => f.Value)
  42.                     .ThenBy(f => f.Key))
  43.                 {
  44.                     Console.WriteLine($"{nameSizePair.Key} - {nameSizePair.Value} KB");
  45.                 }
  46.             }
  47.             catch
  48.             {
  49.                 Console.WriteLine("No");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement