Advertisement
Derga

Untitled

May 27th, 2023 (edited)
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <ctime>
  4. #include <forward_list>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. void GenerateFile(const string& pattern, const string& file_name) {
  10.     string text;
  11.     int WORDS_COUNT = 5;
  12.     srand(time(0));
  13.     for (int i = 0; i < WORDS_COUNT; ++i) {
  14.         int word_size = 1 + rand() % 10;
  15.         string word;
  16.         for (int j = 0; j < word_size; ++j) {
  17.             word += (char)('a' + rand() % 25);
  18.         }
  19.  
  20.         int pattern_chance = rand() % 11;
  21.         if (pattern_chance == 0) {
  22.             text += pattern;
  23.             text += ' ';
  24.         }
  25.  
  26.         if (i == 1 || i == 3) {
  27.             text += pattern;
  28.             text += ' ';
  29.         }
  30.  
  31.         text += word;
  32.         text += ' ';
  33.     }
  34.  
  35.     ofstream fout(file_name, std::ios::binary);
  36.     fout << text;
  37.     fout.close();
  38.  
  39. }
  40.  
  41. void Print(const forward_list<char>& l) {
  42.     auto it = l.begin();
  43.     while (it !=l.end()) {
  44.         cout << *it++;
  45.     }
  46. }
  47.  
  48. int main() {
  49.     string pattern, file_name;
  50.     cin >> pattern >> file_name;
  51.     GenerateFile(pattern, file_name);
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement