Algorithms


Convert Roman numerals to integer numbers  (C++)


Maximum profit or loss in a series of stock prices  (Java)


Print all possible words that a phone number can present (C++, recursive)


int const PHONE_NUMBER_LENGTH = 3;


void PrintKeypadWords(int phoneNum [])

{

    char result[PHONE_NUMBER_LENGTH];

    DoPrintKeypadWords(phoneNum, 0, result);

}


void DoPrintKeypadWords(int phoneNum [], int currDigit, char result[])

{

    if (currDigit == PHONE_NUMBER_LENGTH)

    {

        result[PHONE_NUMBER_LENGTH] = '\0';

        std::cout << result << "\n";

        return;

    }

    

    for (int i = 1; i <= 3; i++)

    {

        result[currDigit] = GetCharKey(phoneNum[currDigit], i);

        DoPrintKeypadWords(phoneNum, currDigit + 1, result);

        if (phoneNum[currDigit] == 0 || phoneNum[currDigit] == 1)

        {

            return;

        }

    }

}


Test:

    int phoneNum[PHONE_NUMBER_LENGTH] = {4,8,2};

    PrintKeypadWords(phoneNum);