1
Projects and Discussion / Re: problem with a project in c++
« on: August 13, 2015, 05:33:46 PM »
Wow..what a subtlety...nice !
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
using namespace std;
int main()
{
string inputWord("MYSTERE"); // I wanted to test it with 1 word before generalizing it
string shuffledWord;
const int wordSize(inputWord.size());
for (int i=0 ; i <= wordSize ; i++)
{
int position(0) ;
srand(time(0));
position = rand() % wordSize;
shuffledWord += inputWord[position];
inputWord.erase(position, 1);
}
cout << "shuffled word :" << shuffledWord<<endl;
return 0;
}
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
/*
this function takes a string as argument and shuffles it */
using namespace std;
int main()
{
string inputWord("MYSTERE"); // I wanted to test it with 1 word before generalizing it
string shuffledWord;
for (int i=0 ; i <= inputWord.size() ; i++)
{
int position(0) ;
srand(time(0));
position = rand() % inputWord.size();
shuffledWord += inputWord[position];
inputWord.erase(5, 1); // Retire la lettre n°5
}
cout << "shuffled word :" << shuffledWord<<endl;
return 0;
}