Modular programming easy to read C++
\nclass Solution {\npublic:\n    vector<string> ambiguousCoordinates(string s) {\n        s = s.substr(1, s.length() - 2);\n        vector<string> result;\n    
```\nclass Solution {\npublic:\n    vector<string> ambiguousCoordinates(string s) {\n        s = s.substr(1, s.length() - 2);\n        vector<string> result;\n        for (int i = 1; i < s.length(); i++)\n        {\n            string str1 = s.substr(0, i), str2 = s.substr(i);\n            vector<string> res1 = genValid(str1), res2 = genValid(str2);\n\n            for (auto& s1 : res1)\n                for (auto& s2 : res2)\n                    genResult(s1, s2, result);\n        }\n        \n        return result;\n    }\n    \n    vector<string> genValid(string& str)\n    {\n        vector<string> res;\n        if (valid(str))\n            res.push_back(str);\n        \n        for (int i = 1; i < str.length(); i++)\n        {\n            string cur = str.substr(0, i) + "." + str.substr(i);\n            if (valid(cur))\n                res.emplace_back(cur);\n        }\n        \n        return res;\n    }\n    \n    bool valid(string& str)\n    {\n        if (str.length() > 1 && str[0] == \'0\' && str[1] != \'.\')\n            return false;\n\n        if (str.back() == \'0\')\n        {\n            for (int i = str.length() - 1; i >= 0; i--)\n                if (str[i] == \'.\')\n                    return false;\n        }\n        \n        return true;\n    }\n    \n    void genResult(string& str1, string& str2, vector<string>& result)\n    {\n        result.emplace_back("(" + str1 + ", " + str2 + ")");\n    }\n};\n```
[]