Advertisement
Guest User

Files

a guest
Sep 26th, 2016
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Files
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             List<string> input = new List<string>();
  15.             //READ DIRECTORIES
  16.             for (int i = 0; i < n; i++){
  17.                 string inputLine = Console.ReadLine();
  18.                 input.Add(inputLine);
  19.             }
  20.             var inputCommand = Console.ReadLine();
  21.             List<string> command = inputCommand.Split().ToList();
  22.             string extension = command[0];
  23.             string place = command[2];
  24.             SortedDictionary<string, int> dictionary = new SortedDictionary<string, int>();
  25.             bool hasSomething = false;
  26.             for (int i = 0; i < input.Count; i++){
  27.                 //CHECK IF INPUT CONTAINS GIVEN DIRECTORY
  28.                 if (input[i].Contains(place)){
  29.                     List<string> splitted = new List<string>();
  30.                     splitted = input[i].Split('\\').ToList();
  31.                     for (int m = 0; m < splitted.Count; m++) {
  32.                         //CHECK IF INPUT CONTAINS GIVEN FILE EXTENTION
  33.                         if (splitted[m].Contains(extension)){
  34.                             hasSomething = true;
  35.                             List<string> files = splitted[m].Split(';').ToList();
  36.                             string file = files[0];
  37.                             int size = int.Parse(files[1]);
  38.                             //CHECK IF DICTIONARY CONTAINS KEY WITH DIFFERENT SIZE
  39.                             if (dictionary.ContainsKey(file) && !dictionary[file].Equals(size)) {
  40.                                 dictionary[file] = size;
  41.                             }
  42.                             else {
  43.                                 dictionary.Add(file, size);
  44.                             }
  45.                         }
  46.                     }
  47.                 }
  48.             }
  49.             //PRINT DICTIONARY IF IT CONTAINS SOMETHING
  50.             if (hasSomething == true)
  51.             {
  52.                 foreach (var pair in dictionary.OrderByDescending(key => key.Value))
  53.                 {
  54.                     Console.WriteLine("{0} - {1} KB", pair.Key, pair.Value);
  55.                 }
  56.             }
  57.             else
  58.             {
  59.                 Console.WriteLine("No");
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement