Skip to content

Instantly share code, notes, and snippets.

@eric-taix
Created February 14, 2014 12:40
Show Gist options
  • Save eric-taix/9000337 to your computer and use it in GitHub Desktop.
Save eric-taix/9000337 to your computer and use it in GitHub Desktop.
Codingame MIME types challenge solution in Dart
// 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