Permuting names with C++

No Comments
One day, talking with a friend of mine, we started for some reason not necessarily known permuting our names to see how many possible combinations we could get from them.
Well doing it with small names is quite easy and fast but with longer ones not that much.

We are programmers then we decided to create a piece of code to the job for us. At first I tought Python would be the best choice for such simple task but since I was with Code::Blocks open I decided to do it in C++ to train some of my skills on the language.

I'm now sharing the simple code of permuting strings;


#include 
#include 
 
using namespace std;
 
void Permute(string word, int times=0)
{
    if(word.length() <= 1 or times == word.length())
    {
        cout << word << endl;
    }
    else
    {
        for(int i = 0; i < word.length(); i++)
        {
            if(i == word.length()-1)
                break;
            cout << word << endl;
            char letter = word[i];
            word[i] = word[i+1];
            word[i+1] = letter;
        }
        Permute(word, times+1);
    }
}
 
int main()
{
    string word;
    cout << "Digite uma palavra: ";
    cin >> word;
    Permute(word, 0);
    return 0;
}

Here is a Pastebin to better visualize the syntax highlights: C++ Permutation