Advertisement
1k6j01

My work

Jun 5th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <vector>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. void order(char x[], int n) //упорядочивание символов
  12. {
  13.     for (int i(0); i < n - 1; i++)
  14.     {
  15.         for (int j(i + 1); j < n; j++)
  16.             if (x[i] > x[j])
  17.                 swap(x[i], x[j]);
  18.     }
  19. }
  20.  
  21. int engine_func(char *alphabet, size_t length, const size_t last_digit)
  22. {
  23.     vector<size_t> number(length, 0); // indices into alphabet
  24.     for (; ; )
  25.     {
  26.         // print number
  27.         for (auto i : number) cout << alphabet[i];
  28.         cout << '\n';
  29.  
  30.         // increment the rightmost digit
  31.         size_t pos = length;
  32.         while (number[--pos] == last_digit)
  33.         { // overflow
  34.             if (pos == 0)
  35.             {
  36.                 return 0; // no more digits
  37.             }
  38.             number[pos] = 0; // set to zero and increment the left neigbor
  39.         }
  40.         ++number[pos];
  41.     }
  42. }
  43.  
  44. int main(int argc, char* argv[])
  45. {  
  46.     cout << "3n73r y0ur k3ys: ";
  47.     char alphabet[50]; //входное слово
  48.     char x;
  49.     int alph_len(0); // для запоминания размера массива
  50.     cin >> x;
  51.     while (x != '/')
  52.     {
  53.         alphabet[alph_len] = x;
  54.         alph_len++;
  55.         cin >> x;
  56.     }
  57.     alphabet[alph_len] = '\0';
  58.     order(alphabet, alph_len);
  59.  
  60.     const size_t last_digit = alph_len - 1; // '\0'
  61.     //const size_t length = 6;
  62.     const size_t min_length = 4;
  63.     const size_t MIN = argc > 1 ? stoul(argv[1]) : 4;
  64.     const size_t length = argc > 1 ? stoul(argv[2]) : 10;
  65.  
  66.     int a;
  67.     for (size_t len = MIN; len < length; len++)
  68.     {
  69.         a = engine_func(alphabet, len, last_digit);
  70.     }
  71.  
  72.     _getch();
  73.     return a;  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement