fork(1) download
  1. #include <string>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5. #include <iostream>
  6. #include <iomanip>
  7.  
  8. int main()
  9. {
  10. using sequence_type = std::vector<std::string> ;
  11. sequence_type seq { "abc", "def", "abc", "ghi", "def", "abc" } ;
  12. std::sort( seq.begin(), seq.end() ) ;
  13.  
  14. std::set<sequence_type> unique_permutations ;
  15.  
  16. do unique_permutations.insert( sequence_type( seq.begin(), seq.end() ) ) ;
  17. while( std::next_permutation( seq.begin(), seq.end() ) ) ;
  18.  
  19. for( const auto& seq : unique_permutations )
  20. {
  21. static int n = 0 ;
  22. std::cout << std::setw(3) << ++n << ". " ;
  23. for( const auto& str : seq ) std::cout << str << ' ' ;
  24. std::cout << '\n' ;
  25. }
  26. }
  27.  
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
  1. abc abc abc def def ghi 
  2. abc abc abc def ghi def 
  3. abc abc abc ghi def def 
  4. abc abc def abc def ghi 
  5. abc abc def abc ghi def 
  6. abc abc def def abc ghi 
  7. abc abc def def ghi abc 
  8. abc abc def ghi abc def 
  9. abc abc def ghi def abc 
 10. abc abc ghi abc def def 
 11. abc abc ghi def abc def 
 12. abc abc ghi def def abc 
 13. abc def abc abc def ghi 
 14. abc def abc abc ghi def 
 15. abc def abc def abc ghi 
 16. abc def abc def ghi abc 
 17. abc def abc ghi abc def 
 18. abc def abc ghi def abc 
 19. abc def def abc abc ghi 
 20. abc def def abc ghi abc 
 21. abc def def ghi abc abc 
 22. abc def ghi abc abc def 
 23. abc def ghi abc def abc 
 24. abc def ghi def abc abc 
 25. abc ghi abc abc def def 
 26. abc ghi abc def abc def 
 27. abc ghi abc def def abc 
 28. abc ghi def abc abc def 
 29. abc ghi def abc def abc 
 30. abc ghi def def abc abc 
 31. def abc abc abc def ghi 
 32. def abc abc abc ghi def 
 33. def abc abc def abc ghi 
 34. def abc abc def ghi abc 
 35. def abc abc ghi abc def 
 36. def abc abc ghi def abc 
 37. def abc def abc abc ghi 
 38. def abc def abc ghi abc 
 39. def abc def ghi abc abc 
 40. def abc ghi abc abc def 
 41. def abc ghi abc def abc 
 42. def abc ghi def abc abc 
 43. def def abc abc abc ghi 
 44. def def abc abc ghi abc 
 45. def def abc ghi abc abc 
 46. def def ghi abc abc abc 
 47. def ghi abc abc abc def 
 48. def ghi abc abc def abc 
 49. def ghi abc def abc abc 
 50. def ghi def abc abc abc 
 51. ghi abc abc abc def def 
 52. ghi abc abc def abc def 
 53. ghi abc abc def def abc 
 54. ghi abc def abc abc def 
 55. ghi abc def abc def abc 
 56. ghi abc def def abc abc 
 57. ghi def abc abc abc def 
 58. ghi def abc abc def abc 
 59. ghi def abc def abc abc 
 60. ghi def def abc abc abc