Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _04_04_Files
- {
- class Files
- {
- static void Main(string[] args)
- {
- // 100% from the very first time!
- Regex rootPattern = new Regex(@"^(?<root>.+?)\\");
- Regex namePattern = new Regex(@"^.*\\(?<fileName>.+\..+?)$");
- Dictionary<string, Dictionary<string, long>> files = new Dictionary<string, Dictionary<string, long>>();
- long n = long.Parse(Console.ReadLine());
- for (long i = 0; i < n; i++)
- {
- string[] data = Console.ReadLine()
- .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
- string path = data[0];
- long size = long.Parse(data[1]);
- string rootName = rootPattern.Match(path).Groups["root"].Value;
- string fileName = namePattern.Match(path).Groups["fileName"].Value;
- if (!files.ContainsKey(rootName))
- {
- files.Add(rootName, new Dictionary<string, long>());
- }
- if (!files[rootName].ContainsKey(fileName))
- {
- files[rootName].Add(fileName, 0);
- }
- files[rootName][fileName] = size;
- }
- string[] query = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string extension = query[0];
- string root = query[2];
- if (!files.ContainsKey(root))
- {
- Console.WriteLine("No");
- }
- else
- {
- Dictionary<string, long> queryFiles = files[root].Where(x => x.Key.EndsWith(extension)).ToDictionary(x => x.Key, x => x.Value);
- if (queryFiles.Count == 0)
- {
- Console.WriteLine("No");
- }
- else
- {
- foreach (KeyValuePair<string, long> file in queryFiles.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{file.Key} - {file.Value} KB");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment