#include <iostream>
#include <algorithm>
#include <string>

bool checkInputNum(std::string strNumber)
{
	if (std::all_of(strNumber.begin(), strNumber.end(), [](unsigned char chNum) {return isdigit(chNum) || isalpha(chNum);}))
		return true;

	return false;
}

bool IsNumValid(std::string strRule, std::string strNum)
{
	if (strRule.length() < strNum.length())
		return false;

	std::string strRevNum(strNum.rbegin(), strNum.rend());
	std::string strRevRule(strRule.rbegin(), strRule.rend());

	for (unsigned int i = 0 ; i < strRevRule.length() ; ++i)
	{
		if (isalpha(strRevRule[i]))
			continue;

		if (isdigit(strRevRule[i]) && i < strRevNum.length() && strRevRule[i] == strRevNum[i])
		{
			continue;
		}
		else
		{
			return false;
		}
	}

	return true;
}

int main()
{
	std::string strMultiplicand, strMultiplier, strAnswer;

	//std::cin >> strMultiplicand;
	//std::cin >> strMultiplier;
	//std::cin >> strMultiplier;

	strMultiplicand = "a1b2";
	strMultiplier = "3c";
	strAnswer = "4d5ef";

	for (int i = 0 ; std::to_string(i).length() <= strMultiplicand.length() ; ++i)
	{
		if (!IsNumValid(strMultiplicand, std::to_string(i)))
			continue;

		for (int j = 0 ; std::to_string(j).length() <= strMultiplier.length() ; ++j)
		{
			if (!IsNumValid(strMultiplier, std::to_string(j)))
				continue;

			if (IsNumValid(strAnswer, std::to_string(i*j)))
			{
				std::cout << i << " * " << j << " = " << i*j << std::endl;
			}
		}
	}

	system("PAUSE");
	return 0;
}
