Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Files
- {
- public class Files
- {
- public static void Main()
- {
- int numberOfRoots = int.Parse(Console.ReadLine());
- Dictionary<string, Dictionary<string, long>> allDirectories =
- new Dictionary<string, Dictionary<string, long>>();
- for (int currRoot = 0; currRoot < numberOfRoots; currRoot++)
- {
- string[] inputLine = Console.ReadLine().Split(';');
- string[] directory = inputLine[0].Split('\\');
- string folderName = directory[0];
- string fileName = directory[directory.Length - 1];
- long fileSize = long.Parse(inputLine[inputLine.Length - 1]);
- if (!allDirectories.ContainsKey(folderName))
- {
- allDirectories.Add(folderName, new Dictionary<string, long>());
- }
- allDirectories[folderName][fileName] = fileSize;
- }
- string[] searchInfo = Console.ReadLine().Split();
- string extensionToSearch = searchInfo[0];
- string folderToSearchIn = searchInfo[2];
- if (!allDirectories.ContainsKey(folderToSearchIn))
- {
- Console.WriteLine("No");
- return;
- }
- bool thereIsMatch = false;
- foreach (KeyValuePair<string, long> fileAndSize in allDirectories[folderToSearchIn]
- .OrderByDescending(f => f.Value)
- .ThenBy(n => n.Key))
- {
- string[] fileInfo = fileAndSize.Key.Split('.');
- string fileExtension = fileInfo[1];
- if (extensionToSearch.Equals(fileExtension))
- {
- thereIsMatch = true;
- Console.WriteLine($"{fileAndSize.Key} - {fileAndSize.Value} KB");
- }
- }
- if (!thereIsMatch)
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement