Created
June 4, 2016 01:26
-
-
Save kadimi/5876cc0f898dbaa7a5c51ac7eef030f8 to your computer and use it in GitHub Desktop.
Codinggame | MIME types solution in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Number of elements which make up the association table. | |
fscanf(STDIN, "%d", $N); | |
// Number Q of file names to be analyzed. | |
fscanf(STDIN, "%d", $Q); | |
// File extensions to MIME types assosciations | |
$ext_to_MIME = array(); | |
for ($i = 0; $i < $N; $i++) { | |
fscanf(STDIN, "%s %s", $EXT, $MT); | |
$ext_to_MIME[$EXT] = $MT; | |
} | |
// Files | |
$files = array(); | |
for ($i = 0; $i < $Q; $i++) { | |
$files[] = stream_get_line(STDIN, 500 + 1, "\n"); | |
} | |
// Génération du Ouput | |
foreach ($files as $file) { | |
// Obtenir l'extension du fichier | |
$parts = explode('.',$file); | |
$extension = end($parts); | |
// Afficher le MIME type ou 'UNKNOWN' | |
echo array_key_exists($extension, $ext_to_MIME) | |
? $ext_to_MIME[$extension] | |
: 'UNKNOWN' | |
; | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment