#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <sstream>
std::vector<std::string> SplitInputString(const std::string& input)
{
std::vector<std::string> tokens;
std::istringstream ss(input);
std::copy(std::istream_iterator<std::string>(ss),
std::istream_iterator<std::string>(),
std::back_inserter(tokens));
return tokens;
}
struct ParsedInputData
{
ParsedInputData(const std::string& command, const std::vector<std::string>& variables)
: command(command)
, variables(variables)
{
}
std::string command;
std::vector<std::string> variables;
};
int main(int argc, const char* argv[])
{
std::vector<std::string> testInputs {"add A B", "add B F", "breadth F", "subtract A B"};
std::vector<ParsedInputData> parsedInputDatas;
for (const auto& input : testInputs)
{
const auto& tokens = SplitInputString(input);
auto parsedInputData = ParsedInputData(tokens.front(), std::vector<std::string>(tokens.begin() + 1, tokens.end()));
parsedInputDatas.push_back(parsedInputData);
}
for (const auto& parsedInputData : parsedInputDatas)
{
std::cout << "Command is: " << parsedInputData.command << std::endl;
std::cout << "Variables: ";
for(const auto& variable : parsedInputData.variables)
{
std::cout << variable << " ";
}
std::cout << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDxzc3RyZWFtPgoKc3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+IFNwbGl0SW5wdXRTdHJpbmcoY29uc3Qgc3RkOjpzdHJpbmcmIGlucHV0KQp7CglzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gdG9rZW5zOwoJCglzdGQ6OmlzdHJpbmdzdHJlYW0gc3MoaW5wdXQpOwoJc3RkOjpjb3B5KHN0ZDo6aXN0cmVhbV9pdGVyYXRvcjxzdGQ6OnN0cmluZz4oc3MpLCAKCQkJICBzdGQ6OmlzdHJlYW1faXRlcmF0b3I8c3RkOjpzdHJpbmc+KCksIAoJCQkgIHN0ZDo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