leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1410.cpp (984B)
0 class Solution { 1 public: 2 string entityParser(const string &text) const { 3 unordered_map<string, char> um = {{""", '"'}, {"'", '\''}, {"&", '&'}, 4 {">", '>'}, {"<", '<'}, {"⁄", '/'}}; 5 6 string res, crnt; 7 for (const char c : text) { 8 if (crnt.empty()) { 9 if (c != '&') 10 res += c; 11 else 12 crnt = "&"; 13 } else { 14 if (c == '&') { 15 res += crnt; 16 crnt = "&"; 17 } else { 18 crnt += c; 19 if (c == ';') { 20 if (um.count(crnt)) 21 res += um[crnt]; 22 else 23 res += crnt; 24 crnt.clear(); 25 } 26 } 27 } 28 } 29 30 return res + crnt; 31 } 32 };