-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmime-type.java
More file actions
42 lines (37 loc) · 1.54 KB
/
mime-type.java
File metadata and controls
42 lines (37 loc) · 1.54 KB
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
/**
* Input
* Line 1: Number N of elements which make up the association table.
*
* Line 2: Number Q of file names to be analyzed.
*
* N following lines: One file extension per line and the corresponding MIME type (separated by a blank space).
*
* Q following lines: One file name per line.
*
* Output
* For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
* Constraints
* 0 < N < 10000
* 0 < Q < 10000
* File extensions are composed of a maximum of 10 alphanumerical ASCII characters.
* MIME types are composed of a maximum 50 alphanumerical and punctuation ASCII characters.
* File names are composed of a maximum of 256 alphanumerical ASCII characters and dots (full stops).
* There are no spaces in the file names, extensions or MIME types.
*
**/
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int types_n = in.nextInt();
int files_n = in.nextInt();
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < types_n; i++) { map.put(in.next().toLowerCase(), in.next()); in.nextLine(); }
for (int i = 0; i < files_n; i++)
{
String FNAME = in.nextLine().toLowerCase(); // One file name per line.
int dotIndex = FNAME.lastIndexOf(".");
String ext = dotIndex == -1 ? "" : FNAME.substring(dotIndex+1);
System.out.println(map.containsKey(ext) ? map.get(ext) : "UNKNOWN");
}
}
}