GarikK

ЗАмена пяти символов в стринге рендомно

Mar 9th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. // PracticeOnlesson.cpp:
  2. //
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <time.h>
  7. using namespace std;
  8. int main()
  9. {
  10.     string a;
  11.     cin >> a;
  12.     srand(time(NULL));
  13.     int randomValues[5];
  14.     int randNumsCounter = 0;
  15.     while (randNumsCounter < 5)
  16.     {
  17.         int tmp = rand() % a.size();
  18.         bool isMatch = false;
  19.         for (int i = 0; i < 5; i++)
  20.         {
  21.             if (randomValues[i] == tmp)isMatch = true;
  22.         }
  23.         if (!isMatch)
  24.         {
  25.             randomValues[randNumsCounter] = tmp;
  26.             randNumsCounter++;
  27.         }
  28.     }
  29.     for (int i = 0; i < 5; i++)
  30.     {
  31.         a[randomValues[i]] = 'A';
  32.     }
  33.     cout << a << endl;
  34. }
Add Comment
Please, Sign In to add comment