{ "question_id": 702251, "question_title": "字符拆分和 反转", "question_content": "将IP\"1.1.168.192\"\n\t\t\t\t变换成 IP\"192.168.1.1\"\n\t\t\t\t只改\"\"内的\n\t\t\t\t返回string类型", "difficulty": "中等", "answer_id": 592646, "answer_content": "\n\n```\n #include \n#include \n#include \n\nusing namespace std;\n\nvector split(const string &s, const string &seperator){\n vector result;\n typedef string::size_type string_size;\n string_size i = 0;\n \n while(i != s.size()){\n //找到字符串中首个不等于分隔符的字母;\n int flag = 0;\n while(i != s.size() && flag == 0){\n flag = 1;\n for(string_size x = 0; x < seperator.size(); ++x)\n if(s[i] == seperator[x]){\n ++i;\n flag = 0;\n break;\n }\n }\n \n //找到又一个分隔符,将两个分隔符之间的字符串取出;\n flag = 0;\n string_size j = i;\n while(j != s.size() && flag == 0){\n for(string_size x = 0; x < seperator.size(); ++x)\n if(s[j] == seperator[x]){\n flag = 1;\n break;\n }\n if(flag == 0) \n ++j;\n }\n if(i != j){\n result.push_back(s.substr(i, j-i));\n i = j;\n }\n }\n return result;\n}\n\nint main() {\n string s = \"1.1.168.192\";\n vector v = split(s, \".\");\n string result = v[v.size() - 1];\n for(vector::size_type i = v.size() - 2; i >= 0; i--)\n {\n result = result + \".\";\n\tresult = result + v[i];\n }\n cout << result;\n}\n```\n\n192.168.1.1", "tag_name": "c++", "cpp": " #include \n#include \n#include \nusing namespace std;\nvector split(const string &s, const string &seperator){\n vector result;\n typedef string::size_type string_size;\n string_size i = 0;\n while(i != s.size()){\n\tint flag = 0;\n\twhile(i != s.size() && flag == 0){\n\t flag = 1;\n\t for(string_size x = 0; x < seperator.size(); ++x)\n\t\tif(s[i] == seperator[x]){\n\t\t ++i;\n\t\t flag = 0;\n\t\t break;\n\t\t}\n\t}\n\tflag = 0;\n\tstring_size j = i;\n\twhile(j != s.size() && flag == 0){\n\t for(string_size x = 0; x < seperator.size(); ++x)\n\t\tif(s[j] == seperator[x]){\n\t\t flag = 1;\n\t\t break;\n\t\t}\n\t if(flag == 0) \n\t\t++j;\n\t}\n\tif(i != j){\n\t result.push_back(s.substr(i, j-i));\n\t i = j;\n\t}\n }\n return result;\n}\nint main() {\n string s = \"1.1.168.192\";\n vector v = split(s, \".\");\n string result = v[v.size() - 1];\n for(vector::size_type i = v.size() - 2; i >= 0; i--)\n {\n\tresult = result + \".\";\n\tresult = result + v[i];\n }\n cout << result;\n}", "topic_link": "https://bbs.csdn.net/topics/600469940", "status": 0, "keywords": "算法高阶,算法问题选编,多项式与快速傅里叶变换", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/31.ipynb?type=file" }, "author": "qq_29902875" }