Skip to content

Instantly share code, notes, and snippets.

@nakov
Created October 30, 2017 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakov/0f7a1d5d93b22e03a1dec77829c3853b to your computer and use it in GitHub Desktop.
Save nakov/0f7a1d5d93b22e03a1dec77829c3853b to your computer and use it in GitHub Desktop.
Files
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
class Files
{
static void Main()
{
var n = int.Parse(Console.ReadLine());
List<string> allFiles = new List<string>();
for (int i = 0; i < n; i++)
{
allFiles.Add(Console.ReadLine());
}
string filter = Console.ReadLine();
var filterTokens = Regex.Split(filter, " in ");
var filterExt = "." + filterTokens[0];
var filterRoot = filterTokens[1] + @"\";
var fileSize = new Dictionary<string, int>();
foreach (var f in allFiles)
{
var filePlusSize = f.Split(';');
var size = int.Parse(filePlusSize[1]);
var path = filePlusSize[0];
if (path.StartsWith(filterRoot) && path.EndsWith(filterExt))
{
var tokens = path.Split('\\');
var fileName = tokens[tokens.Length - 1];
fileSize[fileName] = size;
}
}
var sortedOutputFiles =
fileSize.OrderByDescending(fs => fs.Value)
.ThenBy(fs => fs.Key);
foreach (var file in sortedOutputFiles)
{
Console.WriteLine(file.Key + " - " + file.Value + " KB");
}
if (sortedOutputFiles.Count() == 0)
Console.WriteLine("No");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment