Advertisement
Guest User

Softuni - Files

a guest
Jan 3rd, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 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 fileSize = new Dictionary<string, long>();
  16.             var helpList = new List<string>();
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 string input = Console.ReadLine();
  20.                 var inputHelp = input.Split('\\').ToList();
  21.                 string root = input.Split('\\').ToArray()[0];
  22.                 string fileextSize = input.Split('\\').ToArray().Last();
  23.                 string file = fileextSize.Split(';').ToArray()[0];
  24.                 long size = long.Parse(fileextSize.Split(';').ToArray()[1]);
  25.  
  26.                 string rootFoldersFileSize = $@"{root}\{file}\{size}";
  27.                 helpList.Add(rootFoldersFileSize);
  28.             }
  29.            
  30.             var command = Console.ReadLine().Split(' ').ToArray();
  31.  
  32.             string extCommand = command[0];
  33.             string rootCommand = command[2];
  34.             int count = 0;
  35.             foreach (string item in helpList)
  36.             {
  37.                 var rootFileSize = item.Split('\\').ToArray();
  38.                 string root = rootFileSize[0];
  39.                
  40.                 string file = rootFileSize[1];
  41.  
  42.                
  43.                 if (root == rootCommand && file.Substring(Math.Max(0, file.ToString().Length - extCommand.Length)) == extCommand)
  44.                 {
  45.                     fileSize[file.ToString()] = long.Parse(rootFileSize[2].ToString());
  46.                     count++;
  47.                 }
  48.             }
  49.             if (count == 0)
  50.             {
  51.                 Console.WriteLine("No");
  52.                 return;
  53.             }
  54.             foreach (var pair in fileSize.OrderBy(x=>x.Key).OrderByDescending(x => x.Value))
  55.             {
  56.                 Console.WriteLine($"{pair.Key} - {pair.Value} KB");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement