-
Notifications
You must be signed in to change notification settings - Fork 481
/
1410.cpp
30 lines (28 loc) · 795 Bytes
/
1410.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
class Solution {
public:
string entityParser(string text) {
stringstream res;
int n = text.size(), i = 0;
unordered_map<string, char> entity = {
{""", '\"'},
{"&apos", '\''},
{">", '>'},
{"<", '<'},
{"&frasl", '/'},
{"&", '&'},
};
while (i < n) {
if (text[i] == '&') {
stringstream t;
while (text[i] != ';') {
t << text[i++];
}
string cur = t.str();
if (entity.count(cur)) res << entity[cur];
else res << cur << ";";
} else res << text[i];
i++;
}
return res.str();
}
};