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

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

	long long returnValue = 0;

	if (pointerToWhereYouLeftItLastTime == NULL)
	{
		pointerToWhereYouLeftItLastTime = myString.begin();
	}

	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)
	{
		for (unsigned long long lenght = pointerToWhereYouLeftItLastTime - beginningOfNumber; lenght > 0; lenght--)
		{
			returnValue += (*beginningOfNumber)*(base ^ (lenght - 1));

			beginningOfNumber++;
		}
	}

	return returnValue;
}

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