816. Ambiguous Coordinates.cpp
Code\n\nclass Solution {\npublic:\n    vector<string> ambiguousCoordinates(string S) {\n        for (int i = 2; i < S.size() - 1; i++) {\n            string str
**Code**\n```\nclass Solution {\npublic:\n    vector<string> ambiguousCoordinates(string S) {\n        for (int i = 2; i < S.size() - 1; i++) {\n            string strs[2] = {S.substr(1,i-1), S.substr(i,S.size()-i-1)};\n            xPoss.clear();\n            for (int j = 0; j < 2; j++)\n                if (xPoss.size() || !j) parse(strs[j], j);\n        }\n        return ans;\n    }\nprivate:\n    vector<string> ans, xPoss;\n    void parse(string str, int xy) {\n        if (str.size() == 1 || str.front() != \'0\')\n            process(str, xy);\n        if (str.size() > 1 && str.back() != \'0\')\n            process(str.substr(0,1) + "." + str.substr(1), xy);\n        if (str.size() > 2 && str.front() != \'0\' && str.back() != \'0\')\n            for (int i = 2; i < str.size(); i++)\n                process(str.substr(0,i) + "." + str.substr(i), xy);\n    }\n    void process(string str, int xy) {\n        if (xy)\n            for (auto x : xPoss)\n                ans.push_back("(" + x + ", " + str + ")");\n        else xPoss.push_back(str);\n    }\n};\n```
['C']