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
| #include<sstream> #include<iostream> #include<vector> #include<string> using namespace std;
vector<vector<int>> result; string line = input; string current;
for (auto &c : line) { if (c == '[' || c == ']') current += c; else if (c == ',') current += ' '; else current += c; } istringstream iss(current); string token; while (iss >> token) { if (token[0] == '[') { vector<int> row; while (iss >> token && token[0] != ']') { row.push_back(stoi(token)); } result.push_back(row); } }
|