Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <fstream>
- #include <iterator>
- #include <algorithm>
- #include <ctime>
- #include <cstdlib>
- #define MAX_NOUNS 3
- #define NUM_SENTENCES 10
- typedef std::vector<std::string> Vec;
- void readFile(Vec &vec, const char* fileName){
- std::string str;
- std::ifstream file(fileName);
- if (file.is_open()){
- while (file.good()){
- getline(file, str);
- vec.push_back(str);
- }
- file.close();
- }else
- std::cout
- << "Error opening file: "
- << fileName
- << "."
- << std::endl;
- }
- int main(){
- srand(time(0));
- Vec nouns, verbs, particles;
- readFile(nouns, "nouns.txt");
- readFile(verbs, "verbs.txt");
- readFile(particles, "particles.txt");
- if (nouns.empty() || verbs.empty() || particles.empty())
- return 0;
- for (int i = 0; i != NUM_SENTENCES; ++i){
- int numNouns = rand() % MAX_NOUNS + 1;
- for (int i = 0; i != numNouns; ++i){
- std::cout
- << nouns[rand() % nouns.size()]
- << particles[rand() % particles.size()];
- }
- std::cout
- << verbs[rand() % verbs.size()]
- << "。"
- << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement