Advertisement
_CodeBehind

Files

Feb 23rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5.  
  6. namespace Files
  7. {
  8.     public class Files
  9.     {
  10.         public static void Main()
  11.         {
  12.             var lines = int.Parse(Console.ReadLine());
  13.  
  14.             var result = new Dictionary<string, Dictionary<string, BigInteger>>();
  15.  
  16.             for (int i = 0; i < lines; i++)
  17.             {
  18.                 var currentFile = Console.ReadLine().Split('\\', ';').ToArray();
  19.  
  20.                 var root = currentFile[0];
  21.                 var file = currentFile[currentFile.Length - 2];
  22.                 var fileSize = currentFile.Last();
  23.  
  24.                 if (!result.ContainsKey(root))
  25.                 {
  26.                     result[root] = new Dictionary<string, BigInteger>();
  27.                 }
  28.                 if (!result[root].ContainsKey(file))
  29.                 {
  30.                     result[root][file] = BigInteger.Parse(fileSize);
  31.  
  32.                 }
  33.                 if (result[root].ContainsKey(file))
  34.                 {
  35.                     result[root][file] = BigInteger.Parse(fileSize);
  36.  
  37.                 }
  38.             }
  39.  
  40.             var condition = Console.ReadLine().Split();
  41.  
  42.             var directory = condition.Last();
  43.             var searchExtension = condition[0];
  44.  
  45.             var extension = string.Empty;
  46.             var directoryCounter = 0;
  47.             var count = 0;
  48.  
  49.             foreach (var root in result.Where(x => x.Key == directory))
  50.             {
  51.                 foreach (var fail in root.Value.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  52.                 {
  53.                     directoryCounter++;
  54.  
  55.                     var fileWithExt = fail.Key.Split('.').ToArray();
  56.  
  57.                     extension = fileWithExt.Last();
  58.  
  59.                     if (searchExtension == extension)
  60.                     {
  61.                         Console.WriteLine($"{fail.Key} - {fail.Value} KB");
  62.                     }
  63.                     else
  64.                     {
  65.                         count++;
  66.                     }
  67.                 }
  68.             }
  69.  
  70.             if (count==directoryCounter)
  71.             {
  72.                 Console.WriteLine("No");
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement