Permutations

Write a program to display all possible permutations of a given input string--if the string contains duplicate characters, you may have multiple repeated results. Here is a sample for the input cat
cat,cta,act,atc,tac,tca

Questions by dhairaybablani

Showing Answers 1 - 5 of 5 Answers

Tehan Frago

  • Feb 13th, 2015
 

Here is an answer that considers all possible permutations including duplicates. If, however, you wanted to remove duplicated, you could save the answers into a vector if they are unique then print all the elements.


Code
  1. #include <string>

  2. #include <iostream>

  Was this answer useful?  Yes

Sergey

  • May 4th, 2015
 

Hi Tehan! This is a wrong solution. A string of the size N has N! (N factorial) permutations while you have only N*(N-1) ones
One of the solutions is to use some kind of recursion

  Was this answer useful?  Yes

Rajni kant

  • Aug 27th, 2015
 

Code
  1. #include <iostream>

  2. "

  3. ""abc""abc"

  Was this answer useful?  Yes

neha

  • Aug 27th, 2015
 

Plz see below code

Code
  1. #include <string>

  2.  

  3.  

  4. #include <iostream>

  Was this answer useful?  Yes

Jin Hyuk Cho

  • Feb 3rd, 2016
 

A working example

Code
  1. #include <iostream>

  2. #include <string>

  3. #include <set>

  4. #include <sstream>

  5. // constructing remaining characters

  6. // constructing empty set for results

  7. //cout << onePermute << endl;

  8. " ""Done!"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions