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;
- using System.Threading.Tasks;
- namespace _04_files
- {
- class files
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, Dictionary<string, long>> inputFiles = new Dictionary<string, Dictionary<string, long>>();
- while (n-- > 0)
- {
- string curentFile = Console.ReadLine();
- int index = curentFile.LastIndexOf('\\');
- curentFile = curentFile.Remove(index, 1).Insert(index, "valkata");
- string[] inputTokkens = curentFile
- .Split(new string[] { "valkata" }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string directory = inputTokkens[0];
- string[] file = inputTokkens[1].Split(';').ToArray();
- string fileName = file[0];
- long fileSize = long.Parse(file[1]);
- if (!inputFiles.ContainsKey(directory))
- {
- inputFiles.Add(directory, new Dictionary<string, long>());
- }
- if (!inputFiles[directory].ContainsKey(fileName))
- {
- inputFiles[directory].Add(fileName, fileSize);
- }
- else
- {
- inputFiles[directory][fileName] = fileSize;
- }
- }
- string[] input = Console.ReadLine().Split().ToArray();
- string searchedDirectory = input[2];
- string extension = input[0];
- Dictionary<string, long> searchedFiles = new Dictionary<string, long>();
- foreach (var file in inputFiles)
- {
- if (file.Key.Contains(searchedDirectory + "\\"))
- {
- var values = file.Value;
- foreach (var value in values)
- {
- if(value.Key.Contains("." + extension))
- {
- searchedFiles.Add(value.Key, value.Value);
- }
- }
- }
- }
- if(searchedFiles.Count == 0)
- {
- Console.WriteLine("No");
- }
- else
- {
- var outputFiles = searchedFiles
- .OrderByDescending(o => o.Value)
- .ThenBy(o => o.Key)
- .ToDictionary(x => x.Key, y => y.Value);
- foreach (var file in outputFiles)
- {
- Console.WriteLine($"{file.Key} - {file.Value} KB");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement