PCLP2/test1/02.cpp

45 lines
751 B
C++
Raw Normal View History

2020-05-10 12:22:32 +00:00
#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;
}