Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3.  
  4. char* PrintWow(const char* Wow[], int wowsize)
  5. {
  6. int index = std::rand() % wowsize;
  7. const char* word = Wow[index];
  8. int size1 = strlen(Wow[index]);
  9. index = 0;
  10. while (index < 3)
  11. {
  12. index = std::rand() % 10;
  13. }
  14. int size2 = index;
  15. char* rword = new char[size1 + size2 + 1];
  16. int count = 0;
  17. for (count; count < size1; count++)
  18. {
  19. rword[count] = word[count];
  20. }
  21. rword[count] = ' ';
  22. count += 1;
  23. for (count; count < size1 + size2 + 1; count++)
  24. {
  25. rword[count] = '!';
  26. }
  27. rword[count++] = '\0';
  28. return rword;
  29. }
  30.  
  31. char* PrintSubj(const char* ObjSubj[],int objsubjsize, bool array[][2])
  32. {
  33. bool tmp = 0;
  34. int index = 0;
  35. while (tmp == 0)
  36. {
  37. index = std::rand() % 5;
  38. tmp = array[index][1];
  39. }
  40. const char* word = ObjSubj[index];
  41. int wordlen = std::strlen(word);
  42. char* rword = new char[wordlen];
  43. for (int i = 0; i < wordlen; i++)
  44. {
  45. if (i == 0)
  46. {
  47. rword[i] = word[i];
  48. rword[i] = rword[i] - 32;
  49. }
  50. else rword[i] = word[i];
  51. }
  52. rword[wordlen] = '\0';
  53. return rword;
  54.  
  55. }
  56.  
  57. char* PrintAction(const char* Actions[],int actions)
  58. {
  59. int index = std::rand() % actions;
  60. const char* word = Actions[index];
  61. int size = strlen(Actions[index]);
  62. char* rword = new char[size];
  63. for (size_t i = 0; i < size; i++)
  64. {
  65. rword[i] = word[i];
  66. }
  67. rword[size] = '\0';
  68. return rword;
  69. }
  70.  
  71. char* PrintObj(const char* ObjSubj[], int objsubjsize, bool array[][2])
  72. {
  73. bool tmp = 0;
  74. int index = 0;
  75. while (tmp == 0)
  76. {
  77. index = std::rand() % 5;
  78. tmp = array[index][0];
  79. }
  80. const char* word = ObjSubj[index];
  81. int wordlen = std::strlen(word);
  82. char* rword = new char[wordlen];
  83. for (int i = 0; i < wordlen; i++)
  84. {
  85. rword[i] = word[i];
  86. }
  87. rword[wordlen] = '\0';
  88. return rword;
  89.  
  90. }
  91.  
  92. int main()
  93. {
  94. srand(time(nullptr));
  95. int nnn;
  96. int cnt = 0;
  97. std::cin >> nnn; // Just for generating the needed amount of headlines;
  98. const char* Wow[] = {"Shok", "Skandal", "Ne4uvana naglost"};
  99. int wowsize = 3;
  100. const char* ObjSubj[] = { "rqpa", "baba", "kmet", "bager", "sklad" };
  101. int objsubjsize = 5;
  102. const char* Actions[] = { "sgazi", "zadiga", "namiga na", "precakva", "tarashi" };
  103. int actions = 5;
  104.  
  105. // Here I represent the ohject/subject relation through boolean values in a matrix,
  106. bool relation[5][2];
  107. for (int i = 0; i < 5; i++)
  108. {
  109. for (size_t j = 0; j < 2; j++)
  110. {
  111. relation[i][j] = 1;
  112. }
  113. }
  114. relation[4][1] = false;
  115. char* output;
  116. int len1;
  117. int len2;
  118. int len3;
  119. int len4;
  120. int count = 0;
  121. char* part1;
  122. char* part2;
  123. char* part3;
  124. char* part4;
  125. while (cnt < nnn)
  126. {
  127. part1 = PrintWow(Wow, wowsize);
  128. part2 = PrintSubj(ObjSubj, objsubjsize, relation);
  129. part3 = PrintAction(Actions, actions);
  130. part4 = PrintObj(ObjSubj, objsubjsize, relation);
  131. len1 = strlen(part1);
  132. len2 = strlen(part2);
  133. len3 = strlen(part3);
  134. len4 = strlen(part4);
  135. output = new char[len1 + len2 + len3 + len4 + 3];
  136. for (int i = 0; i < len1; i++)
  137. {
  138. output[count++] = part1[i];
  139. }
  140. output[count++] = ' ';
  141. for (int i = 0; i < len2; i++)
  142. {
  143. output[count++] = part2[i];
  144. }
  145. output[count++] = ' ';
  146. for (int i = 0; i < len3; i++)
  147. {
  148. output[count++] = part3[i];
  149. }
  150. output[count++] = ' ';
  151. for (int i = 0; i < len4; i++)
  152. {
  153. output[count++] = part4[i];
  154. }
  155. output[count++] = '\0';
  156. count = 0;
  157. std::cout << output <<std::endl;
  158. delete[] part1;
  159. //delete[] part2;
  160. //delete[] part3;
  161. //delete[] part4;
  162. //delete[] output;
  163. cnt += 1;
  164. }
  165. return 0;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement