-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1410.cpp
More file actions
33 lines (31 loc) · 984 Bytes
/
Copy path1410.cpp
File metadata and controls
33 lines (31 loc) · 984 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
class Solution {
public:
string entityParser(const string &text) const {
unordered_map<string, char> um = {{""", '"'}, {"'", '\''}, {"&", '&'},
{">", '>'}, {"<", '<'}, {"⁄", '/'}};
string res, crnt;
for (const char c : text) {
if (crnt.empty()) {
if (c != '&')
res += c;
else
crnt = "&";
} else {
if (c == '&') {
res += crnt;
crnt = "&";
} else {
crnt += c;
if (c == ';') {
if (um.count(crnt))
res += um[crnt];
else
res += crnt;
crnt.clear();
}
}
}
}
return res + crnt;
}
};