Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // std::cout
- #include <algorithm> // std::random_shuffle
- #include <vector> // std::vector
- #include <ctime> // std::time
- #include <cstdlib> // std::rand, std::srand
- #include <string>
- #include <sstream>
- using namespace std;
- string to_string(int i)
- {
- stringstream ss;
- ss << i;
- return ss.str();
- }
- string convert(int base, int num)
- {
- string s = "";
- while(num != 0){
- s += to_string(num%base);
- num /= base;
- }
- reverse(s.begin(), s.end());
- return s;
- }
- string gen(vector<string> ar){
- string s, s2 = "";
- for(auto t: ar){
- if(s.find(t) == string::npos){
- s += t;
- }
- }
- reverse(ar.begin(), ar.end());
- for(auto t: ar){
- if(s2.find(t) == string::npos){
- s2 += t;
- }
- }
- if(s.length() > s2.length()){
- return s2;
- }
- else{
- return s;
- }
- }
- int main () {
- int i, n, k, entropy;
- srand(unsigned(time(0)));
- vector<string> nums;
- string t, res;
- cin >> n >> k >> entropy;
- for (int i=0; i<pow(k, n); i++) {
- //cout << convert(k, i);
- nums.push_back(convert(k, i));
- }
- res = gen(nums);
- for (i=0; i<entropy; i++){
- random_shuffle(nums.begin(), nums.end());
- t = gen(nums);
- if(t.length() < res.length()){
- res = t;
- }
- //cout << t << '\n';
- }
- cout << "--------------\n" << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement