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 Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, Dictionary<string, long>> output = new Dictionary<string, Dictionary<string, long>>();
- Dictionary<string, long> NameTypeSize = new Dictionary<string, long>();
- for (int i = 0; i < n; i++)
- {
- string[] data = Console.ReadLine().Split('\\').ToArray();
- string[] data2 = data[data.Length - 1].Split(';');
- string nameAndType = data2[0];
- long fileSize = long.Parse(data2[data2.Length - 1]);
- string root = data[0];
- if (output.ContainsKey(root))
- {
- output[root][nameAndType] = fileSize;
- }
- else
- {
- NameTypeSize = new Dictionary<string, long>();
- NameTypeSize[nameAndType] = fileSize;
- output[root] = NameTypeSize;
- }
- }
- string[] commands = Console.ReadLine().Split();
- string neededRoot = commands[2];
- string neededType = commands[0];
- bool doHaveNeededRoot = false;
- output = output.Where(x => x.Key.Equals(neededRoot)).ToDictionary(x=> x.Key, x=> x.Value);
- NameTypeSize = NameTypeSize.OrderByDescending(y => y.Value).ThenBy(y => y.Key).ToDictionary(y => y.Key, y => y.Value);
- if (output.ContainsKey(neededRoot))
- {
- foreach (KeyValuePair<string, long> item in NameTypeSize)
- {
- string[] nametype = item.Key.Split('.').ToArray();
- string type = nametype[nametype.Length - 1];
- if (type.Equals(neededType))
- {
- Console.WriteLine($"{item.Key} - {item.Value} KB");
- doHaveNeededRoot = true;
- }
- }
- }
- if (doHaveNeededRoot ==false)
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment