Advertisement
Guest User

04. Files

a guest
Oct 21st, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Programming_Fundamentals_Files
  9. {
  10.     class Program
  11.     {
  12.        
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             int n = int.Parse(Console.ReadLine());
  17.  
  18.             Regex r = new Regex(@"^(\w:|\w+)\\(?:.*\\\B|.*\\\b)?(.*);(\d+)$");
  19.  
  20.             Match matche;
  21.  
  22.             Dictionary<string, long> d = new Dictionary<string, long>();
  23.  
  24.             List<string> files = new List<string>();
  25.  
  26.             for (int i = 0; i < n; i++)
  27.  
  28.             {
  29.                 files.Add(Console.ReadLine());
  30.  
  31.             }
  32.  
  33.             Match q = Regex.Match(Console.ReadLine(), @"(\w+) \w+ (.*)");
  34.  
  35.             for (int i = 0; i < files.Count; i++)
  36.  
  37.             {
  38.                 matche = r.Match(files[i]);
  39.  
  40.                 if (matche.Groups[1].Value == q.Groups[2].Value && matche.Groups[2].Value.EndsWith(q.Groups[1].Value)) {
  41.                     try
  42.                     {
  43.                         d.Add(matche.Groups[2].Value, long.Parse(matche.Groups[3].Value));
  44.                     }
  45.                     catch (ArgumentException)
  46.                     {
  47.                         d.Remove(matche.Groups[2].Value);
  48.                         d.Add(matche.Groups[2].Value, long.Parse(matche.Groups[3].Value));
  49.                     }
  50.                 }
  51.  
  52.             }
  53.  
  54.             if (d.Count==0)
  55.                 Console.WriteLine("No");
  56.             else
  57.  
  58.             foreach(KeyValuePair<string, long> kvp in d.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  59.             {
  60.                 Console.WriteLine("{0} - {1} KB",kvp.Key, kvp.Value);
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement