Advertisement
bochkareffsasha

5lab tifhon

Dec 18th, 2021 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <Windows.h>
  4. using namespace std;
  5. void SetColor(int text, int background)  // функция для изменения цветов фона и симфолов
  6. {
  7.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  8.     SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  9. }
  10. string CreateWords(int step)
  11. {
  12.     string word;
  13.     srand(time(NULL) + step);        
  14.     int word_lenght = rand() % 6 + 2;   // случайная длина каждого слова
  15.     for (int letter = 0; letter < word_lenght; letter++)    // создаём слово
  16.     {
  17.         srand(time(NULL)+letter);      
  18.         int word_letter = rand() % 26 + 65;
  19.         word = word + char(word_letter);
  20.         Sleep(1);       // Для увеличения разнообразия слов
  21.     }
  22.     return word;
  23. }
  24. void main()
  25. {
  26.     const int M = 20, N = 10;  // кол-во строк, кол-во столбцов (M = 20, N = 10)
  27.     const int K = 2, L = 7;  // мин. кол-во букв в слове, мак. кол-во букв в слове (K = 2, L = 7)
  28.     int count_mark_words = 0; // счётчик количества помеченных слов
  29.     string arr[M][N]; // задаём массив   
  30.     int step_0 = 0;
  31.     for (int row = 0; row < M; row++) // заполение словами
  32.     {
  33.         for (int col = 0; col < N; col++)
  34.         {
  35.             arr[row][col] = CreateWords(step_0);
  36.             step_0++;
  37.         }
  38.     }
  39.     for (int row = 0; row < M; row++)
  40.     {
  41.         int count_letter_for_mark = 0;
  42.         for (int j = 0; j < N; j++)  // проверка количества букв в строке на кратность трём
  43.         {
  44.             count_letter_for_mark += arr[row][j].size();
  45.         }
  46.         if (count_letter_for_mark % 3 == 0)
  47.         {
  48.             for (int col = 0; col < N; col++)
  49.             {
  50.                 SetColor(2, 0);
  51.                 cout << arr[row][col]<<'\t';
  52.             }
  53.             SetColor(15, 0);
  54.             cout << endl;
  55.             count_mark_words += N;
  56.         }
  57.         else
  58.         {
  59.             for (int col = 0; col < N; col++)  // вывод слов, если количество букв строки не кратно трём
  60.             {
  61.            
  62. i < letter_count; i++)
  63.                 {
  64.                     if ((int(word_1[i]) =   string word_1 = arr[row][col];
  65.                 int letter_count = arr[row][col].size();
  66.                 int vowel_count = 0;
  67.                 for (int i = 0; = 65) or (int(word_1[i]) == 69) or (int(word_1[i]) == 73) or (int(word_1[i]) == 79) or (int(word_1[i]) == 85) or (int(word_1[i]) == 89))
  68.                     {
  69.                         vowel_count++;
  70.                     }
  71.                 }
  72.                 if ((vowel_count * 5) <= (letter_count - vowel_count))  //  проверка на отношение гласных и согласных
  73.                 {
  74.                     SetColor(2, 0);
  75.                     cout << arr[row][col] << '\t';
  76.                     SetColor(15, 0);
  77.                     count_mark_words++;
  78.                 }
  79.                 else
  80.                 {
  81.                     SetColor(15, 0);
  82.                     cout << arr[row][col] << '\t';
  83.                 }
  84.             }
  85.             cout << endl;
  86.         }
  87.     }
  88.     setlocale(LC_ALL, "RUS");
  89.     cout << "Количество выделенных слов = " << count_mark_words << endl;
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement