-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (63 loc) · 1.59 KB
/
main.cpp
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
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
int numElems, numFiles;
cin >> numElems; cin.ignore();
cin >> numFiles; cin.ignore();
map<string, string> table;
for (int i = 0; i < numElems; i++) {
string ext, mt;
cin >> ext >> mt; cin.ignore();
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
table[ext] = mt;
}
for (int i = 0; i < numFiles; i++) {
string fname;
getline(cin, fname);
string ext = fname.substr(fname.find_last_of(".") + 1);
if (ext == fname) {
ext = "";
}
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
if (table.count(ext) == 0) {
cout << "UNKNOWN" << endl;
} else {
cout << table[ext] << endl;
}
}
// To debug: cerr << "Debug messages..." << endl;
}
/* Cool solution by someone else
#include <iostream>
#include <string>
#include <map>
using namespace std;
string toupper(string str)
{
for (auto & c: str) c = toupper(c);
return str;
}
int main()
{
int N, Q;
cin >> N >> Q; cin.ignore();
map<string, string> mime;
for (int i = 0; i < N; i++)
{
string key, value;
cin >> key >> value; cin.ignore();
mime[toupper(key)] = value;
}
string str;
while (getline(cin, str))
{
int pos = str.find_last_of(".");
str = (pos == -1) ? "" : toupper(str.substr(pos +1));
cout << (mime.count(str) ? mime[str] : "UNKNOWN") << endl;
}
}
*/