45 lines
751 B
C++
45 lines
751 B
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
void generatePermutations(vector<char>* chset, int length, string cur = "") {
|
|
if(cur.size() >= length) {
|
|
cout<<cur<<"\n";
|
|
return;
|
|
}
|
|
|
|
for(vector<char>::iterator it = chset->begin(); it < chset->end(); it++) {
|
|
cur.push_back(*it);
|
|
generatePermutations(chset, length, cur);
|
|
cur.pop_back();
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
ios::sync_with_stdio(false);
|
|
|
|
int n;
|
|
cout<<"Char set size: ";
|
|
cin>>n;
|
|
|
|
vector<char> chset;
|
|
for(int i=0; i<n; i++){
|
|
cout<<"Character nr."<<i+1<<": ";
|
|
char c;
|
|
cin>>c;
|
|
chset.push_back(c);
|
|
}
|
|
|
|
int k;
|
|
cout<<"Generated word length: ";
|
|
cin>>k;
|
|
|
|
cout<<"Generated combinations:\n";
|
|
generatePermutations(&chset, k);
|
|
|
|
cout.flush();
|
|
|
|
return 0;
|
|
}
|