Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <random>
- #include <time.h>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "RUS");
- string s1;
- int i;
- int b = 2;
- int c = 0;
- //ввод строки
- while (getline(cin, s1) && s1.length() % 3 != 0)
- cout << "Ошибка! Длина строки должна быть кратная 3 " << endl;
- //проверка на 2!=3 || 2!=1 и замена
- int d = s1.length();
- for (int i = 0; i < d; i += 3)
- {
- for (int k = d-1; k > 1; k -= 3)
- {
- if (s1[k] == s1[k - 1])
- {
- s1[k - 1] = rand() % 26 + 'a';
- }
- }
- for (int j = i; j < i + 2; j += 3)
- {
- if (s1[j] == s1[j + 1])
- {
- s1[j + 1] = rand() % 26 + 'a';
- }
- if ( s1[j] == s1[j + 2])
- {
- s1[j + 2] = rand() % 26 + 'a';
- }
- }
- }
- // разделение по 3 элемента
- for (int i = 0; i < d; i++)
- {
- for (i = -1 + c; i < b; i++)
- {
- cout << s1[i + 1];
- }
- cout << '\0';
- c += 3;
- b += 3;
- }
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement