Created
December 27, 2016 02:12
-
-
Save liuqinh2s/bd4afbf9eb6704a06d626b22546f03e8 to your computer and use it in GitHub Desktop.
数组的转换接口,比如我们经常要用到[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]],怎么把这一串字符串,传值给一个vector<pair<int, int>>& people;呢。这或许要用到字符串解析的代码,解析出来后还要一个一个传值,做轮子,不做白手起家的傻逼。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void form_fun(string s, vector<pair<int, int>>& people){ | |
if(s.at(0)=='[' && s.at(1)=='[' && s.at(s.size()-2)==']' && s.at(s.size()-1)==']'){ | |
pair<int,int> p; | |
for(int i=0;i<s.size();i++){ | |
while(i<s.size() && (s.at(i)>'9' || s.at(i)<'0')) | |
i++; | |
if(i<s.size() && s.at(i)<='9' && s.at(i)>='0'){ | |
string buffer=""; | |
buffer += s.at(i); | |
while(i<s.size() && s.at(i+1)<='9' && s.at(i+1)>='0'){ | |
buffer += s.at(i+1); | |
i++; | |
} | |
stringstream ss ; | |
ss << buffer; | |
ss >> p.first; | |
i++; | |
} | |
while(i<s.size() && (s.at(i)>'9' || s.at(i)<'0')) | |
i++; | |
if(i<s.size() && (s.at(i)<='9' && s.at(i)>='0')){ | |
string buffer=""; | |
buffer += s.at(i); | |
while(i<s.size() && s.at(i+1)<='9' && s.at(i+1)>='0'){ | |
buffer += s.at(i+1); | |
i++; | |
} | |
stringstream ss ; | |
ss << buffer; | |
ss >> p.second; | |
} | |
if(i<s.size()) | |
people.push_back(p); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment