-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleetcode_parser.cpp
More file actions
37 lines (34 loc) · 814 Bytes
/
Copy pathleetcode_parser.cpp
File metadata and controls
37 lines (34 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
vector<vector<int>> vec2d(string s)
{
// s = [[1,2,3],[44,5,62]]
// cin >> s;
vector<string> v;
vector<vector<int>> mat;
stringstream ss(s);
while(ss.good())
{
string sub;
getline(ss,sub,']');
if(sub.size())
{
v.push_back(sub.substr(2,sub.size()-2));
mat.push_back(vector<int>());
}
}
int n = mat.size();
for(int i = 0; i < n; i++)
{
stringstream row(v[i]);
while(row.good())
{
string num;
getline(row, num, ',');
if(num.size()) mat[i].push_back(stoi(num));
}
}
int m = mat[0].size();
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cout << mat[i][j] << " \n"[j == m-1];
return mat;
}