Anonymous Anonymous - 1 month ago
98 0

No description

C++

asdasd

#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	string str = "abcdefghi";
	string num = "0123456789";
	string formula;
	int var1[3];
	int var2[3];
	int var3[3];
	while (1)
	{
		cout << "Enter the formula: ";
		cin >> formula;
		if (formula == "-1")
		{
			cout << "Bye" << endl;
			break;
		}
		else
		{
			for (int i = 0; i < str.length(); i++)
			{
				if (formula.at(0) == str.at(i))
				{
					var1[0] = i;
				}
				if (formula.at(1) == str.at(i))
				{
					var1[1] = i;
				}
				if (formula.at(2) == str.at(i))
				{
					var1[2] = i;
				}
			}
			for (int i = 0; i < str.length(); i++)
			{
				if (formula.at(4) == str.at(i))
				{
					var2[0] = i;
				}
				if (formula.at(5) == str.at(i))
				{
					var2[1] = i;
				}
				if (formula.at(6) == str.at(i))
				{
					var2[2] = i;
				}
			}
			for (int i = 0; i < str.length(); i++)
			{
				if (formula.at(8) == str.at(i))
				{
					var3[0] = i;
				}
				if (formula.at(9) == str.at(i))
				{
					var3[1] = i;
				}
				if (formula.at(10) == str.at(i))
				{
					var3[2] = i;
				}
			}
			if (var1[0] + var2[0] == var3[0] && var1[1] + var2[1] == var3[1] && var1[2] + var2[2] == var3[2])
				cout << var1[0] << var1[1] << var1[2] << "+" << var2[0] << var2[1] << var2[2] << "=" << var3[0] << var3[1] << var3[2] << endl << endl;
			else
				cout << "No Solution!" << endl << endl;
		}
	}
	system("pause");
	return 0;
}