Created
February 14, 2014 12:40
-
-
Save eric-taix/9000337 to your computer and use it in GitHub Desktop.
Codingame MIME types challenge solution in Dart
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
// Codingame MIME types challenge solution in Dart | |
// Eric Taix | |
import 'dart:io'; | |
void main() { | |
int nbAsso = int.parse(stdin.readLineSync()); | |
int nbFile = int.parse(stdin.readLineSync()); | |
Map mimes = new List.generate(nbAsso, (_) => stdin.readLineSync()).map((s) => s.split(' ')).fold({}, (r, s) => r ..[s[0].toLowerCase()] = s[1]); | |
for (int i = 0; i < nbFile; i++) { | |
String file = stdin.readLineSync(); | |
int index = file.lastIndexOf('.'); | |
String ext = index >= 0 && index <= file.length - 2? file.substring(file.lastIndexOf('.')+1).toLowerCase() : ""; | |
print(mimes.containsKey(ext) ? mimes[ext] : "UNKNOWN"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment