Created
October 30, 2017 15:01
-
-
Save nakov/0f7a1d5d93b22e03a1dec77829c3853b to your computer and use it in GitHub Desktop.
Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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