Guest User

Untitled

a guest
Jan 2nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 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 Files
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             var rootFileextSize = new Dictionary<string, Dictionary<string, long>>();
  16.             int count = 0;
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 var input = Console.ReadLine().Split('\\').ToArray();
  20.                 string root = input[0];
  21.                 string file = input.Last().Split(';')[0];
  22.                 long size = long.Parse(input.Last().Split(';')[1]);
  23.  
  24.                 if (!rootFileextSize.ContainsKey(root))
  25.                 {
  26.                     rootFileextSize.Add(root, new Dictionary<string, long>());
  27.                 }
  28.  
  29.                 rootFileextSize[root].Add(file, size);
  30.             }
  31.  
  32.             var command = Console.ReadLine().Split(' ').ToArray();
  33.  
  34.             string rootCommand = command[2];
  35.             string extCommand = command[0];
  36.  
  37.             foreach (var rootFileSize in rootFileextSize.Where(x=> x.Key == rootCommand))
  38.             {
  39.  
  40.                 foreach (var FileSize in rootFileSize.Value)
  41.                 {
  42.                     if (FileSize.Key.Contains(extCommand))
  43.                     {
  44.                         count++;
  45.                     }
  46.                 }
  47.                 if (count == 0)
  48.                 {
  49.                     Console.WriteLine("No");
  50.                     return;
  51.                 }
  52.  
  53.                 foreach (var FileSize in rootFileSize.Value.Where(x=> x.Key.Contains(extCommand)).OrderByDescending(x=>x.Value).ThenBy(x=>  x.Key))
  54.                 {
  55.                     Console.WriteLine($"{FileSize.Key} - {FileSize.Value} KB");
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Add Comment
Please, Sign In to add comment