forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
31 lines (31 loc) · 840 Bytes
/
Solution.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
class Solution {
public:
string entityParser(string text) {
unordered_map<string, string> d;
d["""] = "\"";
d["'"] = "'";
d["&"] = "&";
d[">"] = ">";
d["<"] = "<";
d["⁄"] = "/";
string ans = "";
int i = 0, n = text.size();
while (i < n) {
bool find = false;
for (int l = 1; l < 8; ++l) {
int j = i + l;
if (j <= n) {
string t = text.substr(i, l);
if (d.count(t)) {
ans += d[t];
i = j;
find = true;
break;
}
}
}
if (!find) ans += text[i++];
}
return ans;
}
};