Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ctime>
- #include <forward_list>
- #include <string>
- using namespace std;
- void GenerateFile(const string& pattern, const string& file_name) {
- string text;
- int WORDS_COUNT = 5;
- srand(time(0));
- for (int i = 0; i < WORDS_COUNT; ++i) {
- int word_size = 1 + rand() % 10;
- string word;
- for (int j = 0; j < word_size; ++j) {
- word += (char)('a' + rand() % 25);
- }
- int pattern_chance = rand() % 11;
- if (pattern_chance == 0) {
- text += pattern;
- text += ' ';
- }
- if (i == 1 || i == 3) {
- text += pattern;
- text += ' ';
- }
- text += word;
- text += ' ';
- }
- ofstream fout(file_name, std::ios::binary);
- fout << text;
- fout.close();
- }
- void Print(const forward_list<char>& l) {
- auto it = l.begin();
- while (it !=l.end()) {
- cout << *it++;
- }
- }
- int main() {
- string pattern, file_name;
- cin >> pattern >> file_name;
- GenerateFile(pattern, file_name);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement