Advertisement
YavorGrancharov

04. Files(90%)

Nov 4th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 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.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             BigInteger n = BigInteger.Parse(Console.ReadLine());
  13.  
  14.             Dictionary<string, Dictionary<string, BigInteger>> data =
  15.                 new Dictionary<string, Dictionary<string, BigInteger>>();
  16.  
  17.             for (BigInteger i = 0; i < n; i++)
  18.             {
  19.                 string input = Console.ReadLine();
  20.                 string[] tokens = input
  21.                     .Split(new char[] { '\\', ';', ' '}, StringSplitOptions.RemoveEmptyEntries);
  22.  
  23.                 string root = tokens[0];
  24.                 string fileName = tokens[tokens.Length - 2];
  25.                 BigInteger size = BigInteger.Parse(tokens[tokens.Length - 1]);
  26.  
  27.                 if (!data.ContainsKey(root))
  28.                 {
  29.                     data.Add(root, new Dictionary<string, BigInteger>());
  30.                 }
  31.                 if (!data[root].ContainsKey(fileName))
  32.                 {
  33.                     data[root].Add(fileName, size);
  34.                 }
  35.                 data[root][fileName] = size;
  36.             }
  37.             string search = Console.ReadLine();
  38.  
  39.             string[] tokensOut = search
  40.                 .Split(' ');
  41.  
  42.             string extension = tokensOut[0];
  43.             string rootOut = tokensOut[2];
  44.  
  45.             bool equals = false;
  46.             foreach (var entry in data)
  47.             {
  48.                 string rootDirectory = entry.Key;
  49.                 Dictionary<string, BigInteger> fileAndSize = entry.Value;
  50.                 if (rootDirectory.Contains(rootOut))
  51.                 {
  52.                     foreach (var file in fileAndSize.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  53.                     {
  54.                         if (file.Key.Split('.').Last().Contains(extension))
  55.                         {
  56.                             equals = true;
  57.                             Console.WriteLine("{0} - {1} KB", file.Key, file.Value);
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.             if (equals == false)
  63.             {
  64.                 Console.WriteLine("No");
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement