Advertisement
hurmawe

9.1

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