Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $n = intval(readline());
- $fileDirectory = [];
- for ($i = 0; $i < $n; $i++) {
- $path = readline();
- $info = explode(",", str_replace("\\", ',', $path));
- $rootDir = $info[0];
- $fileInfo = explode(",", str_replace(array(";",), ',', $info[count($info) - 1]));
- $file = trim(str_replace(array(",", " "), "", preg_replace("/[^a-z.]/", ",", $fileInfo[0])), ".");
- $size = $fileInfo[count($fileInfo) - 1];
- if (!key_exists($rootDir, $fileDirectory)) {
- $fileDirectory[$rootDir] = [];
- }
- if (!in_array($file, $fileDirectory[$rootDir])) {
- $fileDirectory[$rootDir][$file] ['size'] = 0;
- }
- $fileDirectory[$rootDir][$file] ['size'] = $size;
- }
- $query = explode(" ", readline());
- $whereToSearch = $query[2];
- $extention = $query[0];
- $contains = false;
- foreach ($fileDirectory as $key => $value) {
- // ksort($value);
- if ($whereToSearch == $key) {
- uksort($value, 'cmp');
- foreach ($value as $k => $item) {
- $pos = strpos($k, $extention);
- if ($pos !== false) {
- $contains = true;
- echo "$k - $item[size] KB\n";
- }
- }
- }
- }
- if (!$contains) {
- echo "No";
- }
- function cmp($a, $b)
- {
- if ($GLOBALS['value'][$a]['size'] == $GLOBALS['value'][$b]['size']) {
- if ($a == $b) {
- return 0;
- }
- return strcmp($a, $b);
- }
- return $GLOBALS['value'][$a]['size'] - $GLOBALS['value'][$b]['size'] > 0 ? -1 : 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement