How to create permutation of 4 letters based on string in C++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <algorithm>

using std::cout;
using std::endl;
using std::string;

int main()
{
	string s = "abcd";

	do	{
		cout << s << endl;
	} while (next_permutation(s.begin(), s.end()));

	cout << endl;

	return 0;
}


/*
run:

abcd
abdc
acbd
acdb
adbc
adcb
bacd
badc
bcad
bcda
bdac
bdca
cabd
cadb
cbad
cbda
cdab
cdba
dabc
dacb
dbac
dbca
dcab
dcba

*/

 



answered May 19, 2018 by avibootz

Related questions

1 answer 202 views
1 answer 137 views
1 answer 158 views
1 answer 160 views
1 answer 180 views
1 answer 170 views
1 answer 154 views
...