mardi 6 décembre 2022

C++ random word generator [closed]

I'm trying to do random word generator which shuffles the letters of each word, so that the first and the last character will stay on original place. I think there is "shuffle" algorithm for this, but I dont know how this should be solved. Would appreciate help.

#include <iostream>
#include <string>
#include <algorithm>
#include <random>

int main()
{
    // This is a random number generator that should be given as parameter to the
    // function of the algorithm library to shuffle letters
    std::minstd_rand generator;

    std::cout << "Enter some text. Quit by entering the word \"END\"." << std::endl;
    std::string word;

    while (std::cin >> word)
    {
        if (word == "END")
        {
            return EXIT_SUCCESS;
        }

        // TODO: implement your solution here
    
        std::cout << word << std::endl;
    }
}

The program would do for example this:

Enter some text. Quit by entering the word "END".
According to a researcher at Cambridge University it
does not matter in what order the letters in a word are END
Aonrcdicg
to
a
rcasheerer
at
Cabrmigde
Uvensriity
it
deos
not
maettr
in
what
oerdr
the
lettres
in
a
word
are



Aucun commentaire:

Enregistrer un commentaire