In: Computer Science
Write a C++ program that inputs (cin) a word from the keyboard and generates several different scrambles of the word without using vectors. The input word can be from 4 to 10 letters in length. The number of scrambles produced depends on the number of letters in the word. e.g. the 4 letter word “lose” would have 4 different scrambles produced and the seven letter word “edition” would have seven different scrambles.
Here is a candidate example:
Input: FLOOR
Scrambles: ROOLF, OOLFR, OLFRO, LOORF, OORFL
Your program must use the same block of code for each input word. There is also the rand() random number generator available.
Test you program with these words:
salt
asteroid
manipulate
Here you go:
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
srand(time(0));
int i,len=0;
string input;
cout<<"Input: ";
cin>>input;
len=input.length();
std::string output = input;
if(output.size() >=4 && output.size() <=10){
for(i=0; i<len; i++)
{
std::random_shuffle(output.begin() , output.end());
std::cout << output << ' ';
}
}
else
{
return 0;
}
}
========================================================
A sign of thumbs up would be appreciated.