SHARE
TWEET

Files

a guest Feb 7th, 2020 215 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $n = intval(readline());
  3. $fileDirectory = [];
  4. for ($i = 0; $i < $n; $i++) {
  5.     $path = readline();
  6.     $info = explode("\\", $path);
  7.     $rootDir = $info[0];
  8.     $fileInfo = explode(";", $info[count($info) - 1]);
  9.     $filename = $fileInfo[0];
  10.     $size = $fileInfo[1];
  11.     $fileParts = explode(".", $filename);
  12.     $extention = $fileParts[count($fileParts) - 1];
  13.     if (!key_exists($rootDir, $fileDirectory)) {
  14.         $fileDirectory[$rootDir] = [];
  15.     }
  16.     if (!key_exists($extention, $fileDirectory[$rootDir])) {
  17.         $fileDirectory[$rootDir][$extention] = [];
  18.     }
  19.     $fileDirectory[$rootDir][$extention][$filename] = $size;
  20. }
  21. $query = explode(" ", readline());
  22. $whereToSearch = $query[2];
  23. $extentionToSearch = $query[0];
  24. if (!key_exists($whereToSearch, $fileDirectory)
  25.     || !key_exists($extentionToSearch, $fileDirectory[$whereToSearch])) {
  26.     echo "No\n";
  27.     return;
  28. }
  29. $dict = $fileDirectory[$whereToSearch][$extentionToSearch];
  30. uksort($dict, function ($a, $b) use ($dict) {
  31.     if ($dict[$a] === $dict[$b]) return strcasecmp($a, $b);
  32.     return $dict[$b] - $dict[$a];
  33. });
  34. foreach ($dict as $filename => $size) {
  35.     echo "$filename - $size KB\n";
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top