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.Text.RegularExpressions;
- using System.Threading.Tasks;
- class _04_Files
- {
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- List<string> fullPaths = new List<string>();
- for (int i = 1; i <= n; i++)
- {
- fullPaths.Add(Console.ReadLine());
- }
- string filter = Console.ReadLine();
- var filterParts = filter
- .Split(new string[] { " in " },
- StringSplitOptions.RemoveEmptyEntries);
- var filterExtension = filterParts[0];
- var filterRoot = filterParts[1];
- DesignateNeededItems(fullPaths, filterExtension, filterRoot);
- }
- public static void DesignateNeededItems(List<string> fullPaths,
- string ext, string root)
- {
- SortedDictionary<string, decimal> result =
- new SortedDictionary<string, decimal>();
- for (int i = 0; i < fullPaths.Count; i++)
- {
- var folders = fullPaths[i]
- .Split('\\').ToList();
- var fileAndSize = folders[folders.Count - 1]
- .Split(';').ToList();
- string start = folders[0];
- string fileName = fileAndSize[0];
- decimal size = decimal.Parse(fileAndSize[1]);
- if (root==start&&fileName.Contains("."+ext))
- {
- result.Add(fileName, size);
- }
- }
- var sortedDict = from entry in result orderby entry.Value ascending select entry;
- if (result.Count == 0)
- {
- Console.WriteLine("No");
- return;
- }
- else
- {
- foreach (var item in sortedDict)
- {
- Console.WriteLine($"{item.Key} - {item.Value} KB");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement