Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // generator_stl
  4. //
  5. // Created by Владислав Голубничий on 15/03/2019.
  6. // Copyright © 2019 Владислав Голубничий. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <math.h>
  12. #include <set>
  13.  
  14.  
  15. using namespace std;
  16.  
  17. class FloatGenerator
  18. {
  19. private:
  20. vector<float> resultFloat;
  21.  
  22. void split(std::vector<std::string>& dest, const std::string& str, const char* delim)
  23. {
  24. char* pTempStr = strdup(str.c_str());
  25. char* pWord = strtok(pTempStr, delim);
  26. while (pWord != NULL)
  27. {
  28. dest.push_back(pWord);
  29. pWord = strtok(NULL, delim);
  30. }
  31.  
  32. free(pTempStr);
  33. }
  34.  
  35. vector<float> StringToFloat(vector<string> splitedString)
  36. {
  37. vector<float> resultFloat;
  38.  
  39. for (int i = 0; i < splitedString.size(); i++)
  40. {
  41. if (resultFloat.size() < splitedString.size())
  42. {
  43. resultFloat.push_back(0);
  44. resultFloat[i] = stof(splitedString[i]);
  45. }
  46.  
  47. }
  48. return resultFloat;
  49. }
  50.  
  51. public:
  52.  
  53. void SetGenereator ()
  54. {
  55. vector<string> resultSplit;
  56. string input;
  57. getline(cin, input);
  58. split(resultSplit, input, ", ");
  59. resultFloat = StringToFloat (resultSplit);
  60.  
  61. sort(resultFloat.begin(), resultFloat.end(), std::greater<float>());
  62.  
  63. resultSplit.clear();
  64. input.clear();
  65. }
  66.  
  67. void GeneratorA()
  68. {
  69. set<float> result;
  70. set<float>::iterator ik;
  71.  
  72. int startNum = 0;
  73. int multBlockSize = 1;
  74. float multBlockValue = 1;
  75.  
  76. while (resultFloat.size() >= multBlockSize) {
  77. startNum = 0;
  78. while (startNum + multBlockSize <= resultFloat.size()) {
  79.  
  80. multBlockValue = 1;
  81. for (int i = startNum ; i < startNum + multBlockSize ; i++) {
  82. multBlockValue *= resultFloat.at(i);
  83. }
  84.  
  85. for (int i = startNum + multBlockSize ; i < resultFloat.size() ; i++ ) {
  86. result.insert(multBlockValue * resultFloat.at(i));
  87. }
  88.  
  89. startNum++;
  90.  
  91. }
  92. multBlockSize++;
  93. }
  94.  
  95. for ( int i = 0 ; i < resultFloat.size() ; i++ ) {
  96. result.insert(resultFloat.at(i));
  97. }
  98. reverse_copy(result.begin(), result.end(), ostream_iterator<float>(cout, "\n"));
  99.  
  100. }
  101.  
  102. void GeneratorB()
  103. {
  104. int maxDegree = 300;
  105. unsigned long int New_size = resultFloat.size();
  106.  
  107. for (int i = 0 ; i < maxDegree ; i++) {
  108. for (int j = 0 ; j < New_size ; j++) {
  109. resultFloat.push_back(resultFloat.at(j));
  110. }
  111. }
  112. sort(resultFloat.begin(), resultFloat.end(), std::greater<float>());
  113.  
  114. set<float> result;
  115. set<float>::iterator ik;
  116.  
  117. int startNum = 0;
  118. int multBlockSize = 1;
  119. float multBlockValue = 1;
  120.  
  121. while (resultFloat.size() >= multBlockSize) {
  122. startNum = 0;
  123. while (startNum + multBlockSize <= resultFloat.size()) {
  124.  
  125. multBlockValue = 1;
  126. for (int i = startNum ; i < startNum + multBlockSize ; i++) {
  127. multBlockValue *= resultFloat.at(i);
  128. }
  129.  
  130. for (int i = startNum + multBlockSize ; i < resultFloat.size() ; i++ ) {
  131. result.insert(multBlockValue * resultFloat.at(i));
  132. }
  133.  
  134. startNum++;
  135.  
  136. }
  137. multBlockSize++;
  138. }
  139.  
  140. for ( int i = 0 ; i < resultFloat.size() ; i++ ) {
  141. result.insert(resultFloat.at(i));
  142. }
  143. ///////// Output
  144.  
  145. int maxCount = 4;
  146. int currentNumber = 0;
  147.  
  148. for (--(ik = result.end()); ik != result.begin(); --ik)
  149. {
  150.  
  151. if (currentNumber < maxCount)
  152. {
  153. std::cout << *ik << endl;
  154. currentNumber++;
  155. }
  156. else
  157. {
  158. cout << "Continue generate? (Y/N)" << endl;
  159. string confirm;
  160. cin >> confirm;
  161. if (confirm == "Y")
  162. {
  163. currentNumber = 0;
  164. ik++;
  165. }
  166. else if (confirm == "N")
  167. {
  168. break;
  169. }
  170. else
  171. {
  172. cout << "Incorrect input, fucking trash !!" << endl;
  173. ik++;
  174. }
  175. }
  176.  
  177. }
  178. }
  179. };
  180.  
  181. int main(int argc, const char * argv[]) {
  182.  
  183. FloatGenerator firstGenerator;
  184. firstGenerator.SetGenereator();
  185. firstGenerator.GeneratorA();
  186. firstGenerator.GeneratorB();
  187.  
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement