SHARE
TWEET

Untitled

a guest Feb 7th, 2020 73 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(",", str_replace("\\", ',', $path));
  7.     $rootDir = $info[0];
  8.     $fileInfo = explode(",", str_replace(array(";",), ',', $info[count($info) - 1]));
  9.     $file = trim(str_replace(array(",", " "), "", preg_replace("/[^a-z.]/", ",", $fileInfo[0])), ".");
  10.     $size = $fileInfo[count($fileInfo) - 1];
  11.     if (!key_exists($rootDir, $fileDirectory)) {
  12.         $fileDirectory[$rootDir] = [];
  13.     }
  14.     if (!in_array($file, $fileDirectory[$rootDir])) {
  15.         $fileDirectory[$rootDir][$file] ['size'] = 0;
  16.     }
  17.     $fileDirectory[$rootDir][$file] ['size'] = $size;
  18. }
  19. $query = explode(" ", readline());
  20. $whereToSearch = $query[2];
  21. $extention = $query[0];
  22. $contains = false;
  23. foreach ($fileDirectory as $key => $value) {
  24.     //  ksort($value);
  25.     if ($whereToSearch == $key) {
  26.  
  27.         uksort($value, 'cmp');
  28.         foreach ($value as $k => $item) {
  29.  
  30.             $pos = strpos($k, $extention);
  31.             if ($pos !== false) {
  32.                 $contains = true;
  33.                 echo "$k - $item[size] KB\n";
  34.             }
  35.  
  36.         }
  37.     }
  38. }
  39. if (!$contains) {
  40.     echo "No";
  41. }
  42. function cmp($a, $b)
  43. {
  44.     if ($GLOBALS['value'][$a]['size'] == $GLOBALS['value'][$b]['size']) {
  45.         if ($a == $b) {
  46.             return 0;
  47.         }
  48.         return strcmp($a, $b);
  49.     }
  50.     return $GLOBALS['value'][$a]['size'] - $GLOBALS['value'][$b]['size'] > 0 ? -1 : 1;
  51. }
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