-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmime_type.cpp
More file actions
61 lines (55 loc) · 1.32 KB
/
mime_type.cpp
File metadata and controls
61 lines (55 loc) · 1.32 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
// Read inputs from stdin. Write outputs to stdout.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int n, q;
string n_str, q_str;
getline(cin, n_str);
n = atoi(n_str.c_str());
getline(cin, q_str);
q = atoi(q_str.c_str());
map<string, string> table;
for (int i = 0; i < n; i++) {
string ext_mime, ext, mime;
getline(cin, ext_mime);
unsigned pos = ext_mime.find(' ');
ext = ext_mime.substr(0, pos);
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
mime = ext_mime.substr(pos+1);
table[ext] = mime;
}
vector<string> files;
for (int i = 0; i < q; i++) {
string file;
getline(cin, file);
transform(file.begin(), file.end(), file.begin(), ::tolower);
files.push_back(file);
}
for (int i = 0; i < q; i++) {
string f = files[i];
unsigned pos = f.rfind('.');
if(pos == -1) {
// no extension
cout << "UNKNOWN" << endl;
}
else {
string f_ext = f.substr(pos + 1);
map<string, string>::iterator it = table.find(f_ext);
if(it == table.end()) {
// extension not found in table
cout << "UNKNOWN" << endl;
}
else {
// extension found in table
string f_mime = it->second;
cout << f_mime << endl;
}
}
}
return 0;
}