hurmawe

9.2

May 19th, 2022 (edited)
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  int counter=0;
  6. void out_povtor(const vector<char> &array)
  7. {
  8.     int count1 = 0;
  9.     int count2 = 0;
  10.     int count3 = 0;
  11.     int count4 = 0;
  12.     for (int i = 0; i < array.size(); i++)
  13.     {
  14.         if (array[i] == 's')
  15.             count1++;
  16.         else if (array[i] == 'w')
  17.             count2++;
  18.         else if (array[i] == 'o')
  19.             count3++;
  20.         else if (array[i] == 'j')
  21.             count4++;
  22.         if (count1 == 2 or count2 == 2 or count3 == 2 or count4 == 2)
  23.         {
  24.             cout << counter << ": ";
  25.             for (int j = 0; j < array.size(); j++)
  26.             {
  27.                 cout << array[j];
  28.  
  29.             }
  30.             counter++;
  31.             cout << endl;
  32.             break;
  33.         }
  34.     }
  35. }
  36. void loop_povtor(vector<char> array, int pos)
  37. {
  38.     if (pos == array.size() - 1)
  39.     {
  40.         array[pos] = 's';
  41.         out_povtor(array);
  42.         array[pos] = 'w';
  43.         out_povtor(array);
  44.         array[pos] = 'o';
  45.         out_povtor(array);
  46.         array[pos] = 'j';
  47.         out_povtor(array);
  48.     }
  49.     else
  50.     {
  51.         array[pos] = 's';
  52.         loop_povtor(array, pos + 1);
  53.         array[pos] = 'w';
  54.         loop_povtor(array, pos + 1);
  55.         array[pos] = 'o';
  56.         loop_povtor(array, pos + 1);
  57.         array[pos] = 'j';
  58.         loop_povtor(array, pos + 1);
  59.     }
  60. }
  61. int main()
  62. {
  63.     int n;
  64.     cout << "Задание 4" << endl << "Введите длину: " << endl;
  65.     cin >> n;
  66.     vector<char> array(n);
  67.     loop_povtor(array, 0);
  68.     cout <<"Общее число:"<< counter;
  69. }
Add Comment
Please, Sign In to add comment