#include <iostream>
#include <string>
#include <vector>
using namespace std;

template <class T>
class Tokenizer {
public:
	 vector<T> parse(string haystack, string separator);
};
template <class T>
vector<T> Tokenizer<T>::parse(string haystack, string separator)
{
	vector<T>result;
	int startPos = 0;
	int lastFoundPos = -1;
	while (true)
	{
		size_t foundPos = haystack.find(separator, startPos);
		if (foundPos != string::npos)
		{
			string token = haystack.substr(startPos, foundPos - startPos);
			startPos = foundPos + separator.length();
			
			result.push_back(stoi(token)); // chua dong bo dc ep kieu o cho nay
			lastFoundPos = foundPos;
		}
		else
		{
			startPos = lastFoundPos + separator.length();
			string token = haystack.substr(startPos, haystack.size() - startPos);
			
			result.push_back(stoi(token));// chua dong bo dc ep kieu o cho nay
			break;
		}
	}
	return result;
}

int main()
{
	//Problem 1 
	/*Tokenizer<string>x;
	string haystack, separator;
	cout << "Input haystack string: ";
	getline(cin, haystack);
	cout << "Input separator string: ";
	getline(cin, separator);
	vector<string>result = x.parse(haystack, separator);
	cout << "Sub strings:" << endl;
	for (int i = 0; i < result.size(); i++)
		cout << result[i] << endl;*/



	//Problem 2 
	string integers;
	Tokenizer<int>m;
	cout << "Input a string of multiple integers: ";
	getline(cin, integers);
	vector<int>kq = m.parse(integers," ");
	cout << "Sub strings:" << endl;
	for (int i = 0; i < kq.size(); i++)
		cout << kq[i] << endl;
	return 0;
}