Guest User

04. Files

a guest
Oct 20th, 2016
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 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.             int n = int.Parse(Console.ReadLine());
  14.             Dictionary<string, Dictionary<string, long>> output = new Dictionary<string, Dictionary<string, long>>();
  15.             Dictionary<string, long> NameTypeSize = new Dictionary<string, long>();
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 string[] data = Console.ReadLine().Split('\\').ToArray();
  19.                 string[] data2 = data[data.Length - 1].Split(';');
  20.  
  21.                 string nameAndType = data2[0];
  22.                 long fileSize = long.Parse(data2[data2.Length - 1]);
  23.                 string root = data[0];
  24.  
  25.                 if (output.ContainsKey(root))
  26.                 {
  27.                     output[root][nameAndType] = fileSize;
  28.                 }
  29.                 else
  30.                 {
  31.                     NameTypeSize = new Dictionary<string, long>();
  32.                     NameTypeSize[nameAndType] = fileSize;
  33.                     output[root] = NameTypeSize;
  34.                 }
  35.             }
  36.             string[] commands = Console.ReadLine().Split();
  37.             string neededRoot = commands[2];
  38.             string neededType = commands[0];
  39.             bool doHaveNeededRoot = false;
  40.             output = output.Where(x => x.Key.Equals(neededRoot)).ToDictionary(x=> x.Key, x=> x.Value);
  41.             NameTypeSize = NameTypeSize.OrderByDescending(y => y.Value).ThenBy(y => y.Key).ToDictionary(y => y.Key, y => y.Value);
  42.             if (output.ContainsKey(neededRoot))
  43.             {
  44.                 foreach (KeyValuePair<string, long> item in NameTypeSize)
  45.                 {
  46.                     string[] nametype = item.Key.Split('.').ToArray();
  47.                     string type = nametype[nametype.Length - 1];
  48.                     if (type.Equals(neededType))
  49.                     {
  50.                         Console.WriteLine($"{item.Key} - {item.Value} KB");
  51.                         doHaveNeededRoot = true;
  52.                     }
  53.                 }
  54.             }
  55.             if (doHaveNeededRoot ==false)
  56.             {
  57.                 Console.WriteLine("No");
  58.             }
  59.            
  60.  
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment