-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0010.cpp
More file actions
40 lines (36 loc) · 853 Bytes
/
E0010.cpp
File metadata and controls
40 lines (36 loc) · 853 Bytes
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
// Problem Code: MIME2
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
string mediaType(unordered_map<string, string> &table, string name){
string token;
unordered_map<string, string>::iterator it;
stringstream ss(string(name.rbegin(), name.rend()));
getline(ss, token, '.');
if(ss.str() == token)
return "unknown";
reverse(token.begin(), token.end());
it = table.find(token);
return (it != table.end()) ? it->second : "unknown";
}
int main()
{
int N, Q;
string extension, media, name;
unordered_map<string, string> table;
cin >> N >> Q;
cin.ignore();
for(int i=1 ; i<=N ; i++){
cin >> extension >> media;
table[extension] = media;
}
for(int i=1 ; i<=Q ; i++){
cin >> name;
cout << mediaType(table, name) << endl;
}
return 0;
}