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 17, 2026, 2:42 pm
Thread Rating:
|
Here's a simple programming problem for you to solve
|
|
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 4:48 am
(This post was last modified: April 28, 2016 at 4:53 am by SteelCurtain.)
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
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
That, sir, is not C.
But very nearly
The fool hath said in his heart, There is a God. They are corrupt, they have done abominable works, there is none that doeth good.
Psalm 14, KJV revised edition
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 7:47 am
(This post was last modified: April 28, 2016 at 8:02 am by bennyboy.)
My contribution. I can't be bothered with pure c either, but I wanted to show pool some recursion:
Code: // ********************* If you're gonna cheat, might as well go for 25 points! ****************
#include <iostream>
#include <string>
using namespace std;
string str;
int digits;
int counter = 0;
// The following appends a series of single characters to whatever comes in-- originally an empty string; so each call will add a new digit //
void printStrings(string curStr, int curDigit){
for (int i = 0; i < str.length(); i++){
string newStr = curStr + str[i];
if (curDigit < digits -1) printStrings (newStr, curDigit +1); // If we aren't on the last digit, keep recursing (i.e. add another digit) //
else { // If we ARE on the last digit, we can just go ahead and print each string //
counter++;
cout << endl << newStr;
}
}
}
int main()
{
cout << "Input some unique characters: " ;
cin >> str ;
cout << "Max length: ";
cin >> digits ;
cout << endl << "Created following strings:" << endl;
printStrings("", 0); // Starts the recursive routine here
cout << endl << endl << "(" << counter << " total)";
return 0;
}http://cpp.sh/5lfu PS It's the one time I'm proud to say: SteelCurtain, mine's smaller than yours!
He can figure it out. The algorithm is there.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<--- (April 28, 2016 at 7:47 am)bennyboy Wrote: PS It's the one time I'm proud to say: SteelCurtain, mine's smaller than yours! Bastard!
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Let's see if what you sissies posted works *cracks knuckles*
Let's see if pool can solve the problem in Brainfuck.
(April 28, 2016 at 4:48 am)SteelCurtain Wrote: I give thumbs down for SC. My input: AB My input: 2 Output: AA BB AB AB |
|
« Next Oldest | Next Newest »
|
Users browsing this thread: 1 Guest(s)






