Skip to content

Instantly share code, notes, and snippets.

@kadimi
Created June 4, 2016 01:26
Show Gist options
  • Save kadimi/5876cc0f898dbaa7a5c51ac7eef030f8 to your computer and use it in GitHub Desktop.
Save kadimi/5876cc0f898dbaa7a5c51ac7eef030f8 to your computer and use it in GitHub Desktop.
Codinggame | MIME types solution in PHP
<?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