#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;
long long stringToLongLong(string myString, unsigned short base = 10)
{
	std::string::iterator beginningOfNumber = myString.begin(), 
		pointerToWhereYouLeftItLastTime = myString.begin();

	long long returnValue = 0;	

	if (base >= 2 || base <= 10)
	{
		while (pointerToWhereYouLeftItLastTime != myString.end() && (*pointerToWhereYouLeftItLastTime < 48 || *pointerToWhereYouLeftItLastTime > 48 + base - 1))
		{
			pointerToWhereYouLeftItLastTime++;
		}

		if (pointerToWhereYouLeftItLastTime != myString.end())
		{
			beginningOfNumber = pointerToWhereYouLeftItLastTime;
		}
		while (pointerToWhereYouLeftItLastTime != myString.end() && *pointerToWhereYouLeftItLastTime >= 48 && *pointerToWhereYouLeftItLastTime <= 48 + base - 1)
		{
			pointerToWhereYouLeftItLastTime++;
		}
	}
	else if (base <= 16)
	{
		while (pointerToWhereYouLeftItLastTime != myString.end() && (*pointerToWhereYouLeftItLastTime < 48 || *pointerToWhereYouLeftItLastTime > 57) && (*pointerToWhereYouLeftItLastTime < 65 || *pointerToWhereYouLeftItLastTime > 65 + base - 11) && (*pointerToWhereYouLeftItLastTime < 97 || *pointerToWhereYouLeftItLastTime > 97 + base - 11))
		{
			pointerToWhereYouLeftItLastTime++;
		}

		if (pointerToWhereYouLeftItLastTime != myString.end())
		{
			beginningOfNumber = pointerToWhereYouLeftItLastTime;
		}
		while (pointerToWhereYouLeftItLastTime != myString.end() && (*pointerToWhereYouLeftItLastTime >= 48 && *pointerToWhereYouLeftItLastTime <= 57 || *pointerToWhereYouLeftItLastTime >= 65 && *pointerToWhereYouLeftItLastTime <= 65 + base - 11 || *pointerToWhereYouLeftItLastTime >= 97 && *pointerToWhereYouLeftItLastTime <= 97 + base - 11))
		{
			pointerToWhereYouLeftItLastTime++;
		}
	}

	if (beginningOfNumber < myString.end())
	{
		for (unsigned long long lenght = pointerToWhereYouLeftItLastTime - beginningOfNumber; lenght > 0; lenght--)
		{
			returnValue += (*beginningOfNumber - '0')*std::pow(base,  (lenght - 1));

			beginningOfNumber++;
		}
	}

	return returnValue;
}

int main()
{
	string s = "1000";
	long long l = stringToLongLong(s);
	std::cout << l << std::endl;
}