Advertisement
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 _4.Files
- {
- public class Files
- {
- public static void Main()
- {
- var dictionary = new Dictionary<string, Dictionary<string, long>>();
- var n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- var currentFileData = Console.ReadLine().Split('\\');
- var fileRoot = currentFileData[0];
- var fileNameExtensionAndSize = currentFileData[currentFileData.Length - 1].Split(';');
- var fileNameAndExtension = fileNameExtensionAndSize[0];
- var fileSize = long.Parse(fileNameExtensionAndSize[1]);
- if ( !dictionary.ContainsKey(fileRoot) )
- {
- dictionary[fileRoot] = new Dictionary<string, long>();
- }
- dictionary[fileRoot][fileNameAndExtension] = fileSize;
- }
- var filesToSearch = Console.ReadLine().Split().ToList();
- var extension = filesToSearch[0];
- var root = filesToSearch[2];
- if ( !dictionary.ContainsKey(root) )
- {
- Console.WriteLine("No");
- Environment.Exit(1);
- }
- var resultDictionary = dictionary[root]
- .Where(x => x.Key.EndsWith(extension))
- .OrderByDescending(x => x.Value)
- .ThenBy(x => x.Key)
- .ToDictionary(x => x.Key, y => y.Value); ;
- if ( resultDictionary.Count == 0 )
- {
- Console.WriteLine("No");
- Environment.Exit(1);
- }
- foreach ( var file in resultDictionary )
- {
- Console.WriteLine($"{file.Key} - {file.Value} KB");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement