codingame/FACILE/MIME Type/script.php
2015-03-02 19:42:39 +01:00

46 lines
954 B
PHP

<?php
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
fscanf(STDIN, "%d",
$N // Number of elements which make up the association table.
);
fscanf(STDIN, "%d",
$Q // Number Q of file names to be analyzed.
);
$mimes = [];
$files = [];
for ($i = 0; $i < $N; $i++)
{
fscanf(STDIN, "%s %s",
$EXT, // file extension
$MT // MIME type.
);
$mimes[strtolower($EXT)] = $MT;
}
for ($i = 0; $i < $Q; $i++)
{
$files[] = stream_get_line(STDIN, 500, "\n");
}
foreach ($files as $file) {
$e = explode('.', $file);
if (count($e) < 2) {
echo("UNKNOWN\n");
continue;
}
$ext = strtolower(array_pop($e));
echo isset($mimes[$ext]) ? $mimes[$ext] : 'UNKNOWN', "\n";
}
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));