-
Notifications
You must be signed in to change notification settings - Fork 0
/
Easy 08 MIME Type.php
58 lines (48 loc) · 1.45 KB
/
Easy 08 MIME Type.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?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.
);
//Считываем в массив миме-типы
$mimeTypes = [];
for ($i = 0; $i < $N; $i++)
{
fscanf(STDIN, "%s %s",
$EXT, // file extension
$MT // MIME type.
);
$EXT = strtolower($EXT);
$mimeTypes [$EXT] = $MT;
}
$fileTypes = [];
//Считываем данные файлов в массив
for ($i = 0; $i < $Q; $i++)
{
$FNAME = stream_get_line(STDIN, 500, "\n"); // One file name per line.
//list($fileName, $fileType) = explode(".", $FNAME);
$fileType = substr(strrchr($FNAME, "."), 1 );
$fileType = strtolower($fileType);
$fileTypes[$i] = $fileType;
}
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));
//echo("UNKNOWN\n"); // For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
for ($i = 0; $i < $Q; $i++)
{
//Проверка существования расширения в массиве по ключам
if (array_key_exists($fileTypes[$i], $mimeTypes))
{
echo $mimeTypes[$fileTypes[$i]]."\n";
}
else
{
echo("UNKNOWN\n");
}
}
?>