fork(10) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. void combinations(const string& s, vector<int>& pos, int n) {
  7. if (n == s.size()) {
  8. for (int i = 0 ; i != n ; i++) {
  9. cout << s[pos[i]];
  10. }
  11. cout << endl;
  12. return;
  13. }
  14. for (int i = 0 ; i != s.size(); i++) {
  15. pos[n] = i;
  16. combinations(s, pos, n+1);
  17. }
  18. }
  19.  
  20. int main() {
  21. string s("ABC");
  22. vector<int> pos(s.size(), 0);
  23. combinations(s, pos, 0);
  24. return 0;
  25. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
AAA
AAB
AAC
ABA
ABB
ABC
ACA
ACB
ACC
BAA
BAB
BAC
BBA
BBB
BBC
BCA
BCB
BCC
CAA
CAB
CAC
CBA
CBB
CBC
CCA
CCB
CCC