tochka

Files

Mar 31st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 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 ConsoleApp115
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, long> data = new Dictionary<string, long>();
  14.  
  15.             int n = int.Parse(Console.ReadLine());
  16.  
  17.             List<string> values = new List<string>();
  18.  
  19.             for (int i = 0; i < n; i++)
  20.             {
  21.                 string info = Console.ReadLine();
  22.                 values.Add(info);
  23.             }
  24.  
  25.             string[] lookFor = Console.ReadLine()
  26.                 .Split(new string[] { " in " }, StringSplitOptions.RemoveEmptyEntries)
  27.                 .ToArray();
  28.  
  29.             string extention = lookFor[0];
  30.             string root = lookFor[1];
  31.  
  32.             foreach (var item in values)
  33.             {
  34.                 var dotSplit = item.Substring(item.LastIndexOf('.') + 1);
  35.                
  36.                 if (item.StartsWith(root) && dotSplit.StartsWith(extention))
  37.                 {
  38.                     string output = item.Substring(item.LastIndexOf('\\') + 1);
  39.                     string[] splitOutput = output.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  40.  
  41.                     string filenameAndExtention = splitOutput[0];
  42.                     long size = long.Parse(splitOutput[1]);
  43.  
  44.                     if (!data.ContainsKey(filenameAndExtention))
  45.                     {
  46.                         data.Add(filenameAndExtention, size);
  47.                     }
  48.                     else
  49.                     {
  50.                         data[filenameAndExtention] = size;
  51.                     }
  52.                 }
  53.             }
  54.  
  55.             if (data.Count == 0)
  56.             {
  57.                 Console.WriteLine("No");
  58.             }
  59.             else
  60.             {
  61.                 foreach (var file in data.OrderByDescending(a => a.Value).ThenBy(a => a.Key))
  62.                 {
  63.                     if(file.Key.StartsWith(" "))
  64.                     {
  65.                         Console.WriteLine($"{file.Key.Remove(0, 1)} - {file.Value} KB");
  66.                     }
  67.                     else
  68.                     {
  69.                         Console.WriteLine($"{file.Key} - {file.Value} KB");
  70.                     }
  71.                    
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment