Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- 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;
- }
Add Comment
Please, Sign In to add comment