-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmime_type.java
More file actions
66 lines (57 loc) · 2.08 KB
/
mime_type.java
File metadata and controls
66 lines (57 loc) · 2.08 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.*;
import java.io.*;
import java.math.*;
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int N = in.nextInt(); // Number of elements which make up the association table.
in.nextLine();
int Q = in.nextInt(); // Number Q of file names to be analyzed.
in.nextLine();
String EXT [] = new String[N];
String MT[] = new String[N];
String FNAME[] = new String[Q];
for (int i = 0; i < N; i++) {
EXT[i] = in.next(); // file extension
MT[i] = in.next(); // MIME type.
in.nextLine();
}
for (int i = 0; i < Q; i++) {
FNAME[i] = in.nextLine(); // One file name per line.
}
for (int i = 0; i < Q; i++) {
boolean yes = false;
int k, m = 1;
if(FNAME[i].contains(".")){
for(k = FNAME[i].indexOf(".")-1; k < FNAME[i].length()-1; k++){
if(FNAME[i].substring(FNAME[i].indexOf(".")+k) == "." && FNAME[i].substring(FNAME[i].indexOf(".")+k+1) == ".")
m++;
}}
for (int j = 0; j < N; j++) {
if(FNAME[i].contains(".")){
System.out.println(m);
System.out.println(FNAME[i].substring(FNAME[i].indexOf(".")+m));
if(egal(FNAME[i].substring(FNAME[i].indexOf(".")+m), EXT[j])){
if(FNAME[i].substring(0, FNAME[i].length() - FNAME[i].indexOf(".")-m) != "")
System.out.println(MT[j]);
yes = true;
break;
}
}
}
if(!yes)
System.out.println("UNKNOWN");
}
}
public static boolean egal(String str1, String str2){
if(str1.length() != str2.length())
return false;
else
for(int i = 0; i < str1.length(); i++){
String c2 = "" + str2.charAt(i);
if(str1.charAt(i) != c2.toLowerCase().charAt(0) && str1.charAt(i) != c2.toUpperCase().charAt(0))
return false;
}
return true;
}
}