Im trying to solve this in C However Im stuck Only loops and

I\'m trying to solve this in C. However, I\'m stuck. Only loops and arrays allowed. Please help.

Given the format string (11 characters, without space) in the form of ABC+DEF=GHI, where A, B, C, D, E, F, G, H, I are representing decimal digit (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) \"placeholders\" (not necessarily distinct!), develop and implement an algorithm to nd the 3-digit positive numbers (ABC, DEF, and GHI) that give maximum GHI according to the equality given. The letters (A, B, C, D, E, F, G, H, I) are \"place- holders\", so you may have repeating digits. For example in the formula ABA+BBB=GGB, all B\'s represent the same decimal digit. Your algorithm should also check if such numbers are not possible to nd. For example, for the formula AAB+AAB=AAB, it is not possible to satisfy it with decimal digits. Your program will tell \"No solution!\".There might be more than one solution. In this case just output the rst one your algorithm nds. Continue till the user enter -1 for the formula for which your program will exit by saying \"Bye!\".

Sample Run:

Enter the formula:AAB+AAB=AAB
No solution!
Enter the formula:AAA+BBB=AAA
999+000=999
Enter the formula: -1
Bye!

Solution

#include<iostream>

#include<cmath>

#include<string>

using namespace std;

int main()

{

    string string = \"abcdefghijklmnop\";

    string number = \"0123456789\";

    string formulahere;

    int variable1[3];

    int varable2[3];

    int variable3[3];

    while (1)

{

    cout << \"Please Enter the formula: \";

    cin >> formulahere;

    if (formulahere == \"-1\")

    {

        cout << \"wrong .Bye\" << endl;

        break;

    }

    else

    {

        for (int i = 0; i < string.length(); i++)

        {

            if (formulahere.at(0) == string.at(i))

            {

                variable1[0] = i;

            }

            if (formulahere.at(1) == string.at(i))

            {

                variable1[1] = i;

            }

            if (formulahere.at(2) == string.at(i))

            {

                variab1e[2] = i;

            }

        }

        for (int i = 0; i < string.length(); i++)

        {

            if (formulahere.at(4) == stringat(i))

            {

                variable2[0] = i;

            }

            if (formulahere.at(5) == string.at(i))

            {

                variable2[1] = i;

            }

            if (formulahere.at(6) == string.at(i))

            {

                variable2[2] = i;

            }

        }

        for (int i = 0; i < string.length(); i++)

        {

            if (formulahere.at(8) == string.at(i))

            {

                variable3[0] = i;

            }

            if (formulahere.at(9) == string.at(i))

            {

                variable3[1] = i;

            }

            if (formulahere.at(10) == string.at(i))

            {

                var3[2] = i;

            }

        }

        if (variable1[0] + variable2[0] == variable3[0] && variable1[1] + variable2[1] == variable3[1] && variable1[2] + variable2[2] == variable3[2])

            cout << variable1[0] << variable1[1] << variable1[2] << \"+\" << variable2[0] << variable2[1] << variable2[2] << \"=\" << variable3[0] << variable3[1] << variable3[2] << endl << endl;

        else

            cout << \"No Solution!\" << endl << endl;

    }

}

system(\"pause\");

return 0;

}

Output:evaluating AAC+BBF=GHI            

I\'m trying to solve this in C. However, I\'m stuck. Only loops and arrays allowed. Please help. Given the format string (11 characters, without space) in the f
I\'m trying to solve this in C. However, I\'m stuck. Only loops and arrays allowed. Please help. Given the format string (11 characters, without space) in the f
I\'m trying to solve this in C. However, I\'m stuck. Only loops and arrays allowed. Please help. Given the format string (11 characters, without space) in the f

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site