Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: November 30, 2024, 3:28 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Here's a simple programming problem for you to solve
#40
RE: Here's a simple programming problem for you to solve
(April 28, 2016 at 4:48 am)SteelCurtain Wrote:
Code:
// *********************Pool's Homework****************

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

using namespace std;

int main()
{
    //initialize variables
    string str;
    int integ, len, iter, count;
    
    //get the string and the length of output
    cout << "Input the string: " << endl;
    cin >> str;
    cout << "Input an integer: " << endl;
    cin >> integ;
    
    iter = 1; //iterator for exponent
    count = 0; //iterator for number of combinations
    len = str.length(); // how many letters
    const int COMB = pow(len, integ); //number of combinations
    string solutions[COMB]; //an array of strings to concatenate the solutions into

    for (int i = 0; i < integ; i++)
    {    
        while (count <= COMB-1)
        {
            for(int j = 0; j < len; j++) //ab
            {
                for(int k = 0; k < pow(len,(integ-iter)); k++)
                {
                    solutions[count] += str[j];
                    count++;
                }
            }
            
            
        }
        iter++;
        count = 0;
    }


    //print solutions
    cout << endl << endl << "There are " << COMB << " string combinations." << endl;
    cout << "String Combinations:" << endl;
    for (int i = 0; i < COMB; i++)
        cout << solutions[i] << endl;
    
    return 0;
}

You're welcome. You can PayPal me the $2k we agreed upon.

http://cpp.sh/2vh7d

I give thumbs down for SC.
My input: AB
My input: 2
Output:
AA
BB
AB
AB
Reply



Messages In This Thread
RE: Here's a simple programming problem for you to solve - by ErGingerbreadMandude - April 28, 2016 at 9:14 am

Possibly Related Threads...
Thread Author Replies Views Last Post
  Cryptocurrency in simple details. WinterHold 49 5298 September 10, 2021 at 11:02 am
Last Post: Spongebob
  Programming Language Swift Poll Shining_Finger 24 4965 December 2, 2015 at 7:21 pm
Last Post: bennyboy
  Programming Question Shining_Finger 8 1591 December 2, 2015 at 5:30 pm
Last Post: Tiberius
  Programming the Human Mind: Shining_Finger 21 5292 November 24, 2015 at 7:56 pm
Last Post: bennyboy
  Anyone into Android programming? emjay 97 21428 September 20, 2015 at 6:50 am
Last Post: bennyboy
  Advice Sought for Web Programming AFTT47 13 3831 April 4, 2015 at 10:41 pm
Last Post: bennyboy



Users browsing this thread: 1 Guest(s)