Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _04.Files
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- class File
- {
- public string Name { get; set; }
- public string Extension { get; set; }
- public long Memory { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var filesCount = int.Parse(Console.ReadLine());
- var roots = new Dictionary<string, List<File>>();
- for (int i = 0; i < filesCount; i++)
- {
- var file = new File();
- var path = Console.ReadLine().Trim();
- var items = path
- .Split(new[] { '\\', },
- StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- var fileFullName = Regex.Match(items.Last(), @"([a-zA-Z0-9]+)\.([a-z]+)");
- var root = items.First();
- file.Name = fileFullName.Result("$1").ToString();
- file.Extension = fileFullName.Result("$2").ToString();
- file.Memory = long.Parse(items
- .Last()
- .Split(';')
- .Last());
- if (!roots.ContainsKey(root))
- {
- roots[root] = new List<File>();
- roots[root].Add(file);
- }
- else
- {
- bool exists = true;
- foreach (var item in roots[root])
- {
- if (item.Name == file.Name && item.Extension == file.Extension)
- {
- item.Memory = file.Memory;
- exists = true;
- continue;
- }
- else
- {
- exists = false;
- }
- }
- if (!exists)
- {
- roots[root].Add(file);
- }
- }
- }
- var query = Console.ReadLine()
- .Split(new[] { ' ' },
- StringSplitOptions.RemoveEmptyEntries);
- var searchExtension = query[0];
- var searchRoot = query[2];
- var searchFiles = new HashSet<File>();
- foreach (var root in roots)
- {
- if (root.Key == searchRoot)
- {
- foreach (var file in root.Value)
- {
- if (file.Extension == searchExtension)
- {
- searchFiles.Add(file);
- }
- }
- }
- }
- if (searchFiles.Count != 0)
- {
- foreach (var file in searchFiles
- .OrderByDescending(f => f.Memory)
- .ThenBy(f => f.Name))
- {
- Console.WriteLine($"{file.Name}.{file.Extension} - {file.Memory} KB");
- }
- }
- else
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement