Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <iostream>
- #include <stdlib.h>
- #include <conio.h>
- #include <vector>
- #include <string>
- using namespace std;
- void order(char x[], int n) //упорядочивание символов
- {
- for (int i(0); i < n - 1; i++)
- {
- for (int j(i + 1); j < n; j++)
- if (x[i] > x[j])
- swap(x[i], x[j]);
- }
- }
- int engine_func(char *alphabet, size_t length, const size_t last_digit)
- {
- vector<size_t> number(length, 0); // indices into alphabet
- for (; ; )
- {
- // print number
- for (auto i : number) cout << alphabet[i];
- cout << '\n';
- // increment the rightmost digit
- size_t pos = length;
- while (number[--pos] == last_digit)
- { // overflow
- if (pos == 0)
- {
- return 0; // no more digits
- }
- number[pos] = 0; // set to zero and increment the left neigbor
- }
- ++number[pos];
- }
- }
- int main(int argc, char* argv[])
- {
- cout << "3n73r y0ur k3ys: ";
- char alphabet[50]; //входное слово
- char x;
- int alph_len(0); // для запоминания размера массива
- cin >> x;
- while (x != '/')
- {
- alphabet[alph_len] = x;
- alph_len++;
- cin >> x;
- }
- alphabet[alph_len] = '\0';
- order(alphabet, alph_len);
- const size_t last_digit = alph_len - 1; // '\0'
- //const size_t length = 6;
- const size_t min_length = 4;
- const size_t MIN = argc > 1 ? stoul(argv[1]) : 4;
- const size_t length = argc > 1 ? stoul(argv[2]) : 10;
- int a;
- for (size_t len = MIN; len < length; len++)
- {
- a = engine_func(alphabet, len, last_digit);
- }
- _getch();
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement