Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <vector>
- #include <sstream>
- #include <iostream>
- using VS = std::vector<std::string>;
- using VVS = std::vector<VS>;
- using VChars = std::vector<const char*>;
- using VVChars= std::vector<VChars>;
- VS split(const std::string &s, const char delimiter)
- {
- std::stringstream ss(s);
- std::string segment;
- VS lst;
- while(std::getline(ss, segment, delimiter))
- if (segment.size())
- lst.push_back(segment);
- return lst;
- }
- int main(int argc, char *argv[])
- {
- std::string inp;
- std::getline(std::cin, inp);
- VS segPipes = split(inp, '|');
- VVS vCmds;
- VVChars vCommands;
- for (unsigned i = 0; i < segPipes.size(); ++i)
- { vCmds.push_back(split(segPipes[i], ' ')); }
- for (unsigned i = 0; i <vCmds.size(); ++i)
- {
- VChars v;
- for (unsigned k = 0; k < vCmds[i].size(); ++k)
- {
- v.push_back(vCmds[i][k].c_str());
- }
- v.push_back((char*)NULL);
- vCommands.push_back(v);
- }
- for (auto & v:vCommands)
- {
- for(auto &s:v) if (s) std::cout << s<< " ";
- else std::cout << "NULL ";
- std::cout <<"|" << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement