Advertisement
Guest User

OR

a guest
Jan 19th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <ctime>
  6. #include <omp.h>
  7.  
  8. using namespace std;
  9.  
  10. int sum, a, b, c, ld, lj, poLewej = 4, licz = 0, licz_operacje = 0;
  11. string aS, bS, cS, liczba;
  12.  
  13. int main()
  14. {
  15. string s("0123456789");
  16.  
  17. double start = omp_get_wtime();
  18.  
  19. for (int i = 0; i < 99; i++)
  20. {
  21. c = 98 - i;
  22.  
  23. if (c > 9 && c % 11 != 0)
  24. {
  25. liczba = to_string(c);
  26. ld = (liczba.at(0)) - '0';
  27. lj = (liczba.at(1)) - '0';
  28.  
  29. if (ld > lj)
  30. {
  31. s.erase(ld, 1);
  32. s.erase(lj, 1);
  33. }
  34. else
  35. {
  36. s.erase(lj, 1);
  37. s.erase(ld, 1);
  38. }
  39. }
  40. else if (c % 11 != 0)
  41. {
  42. s.erase(c, 1);
  43. poLewej = 5;
  44. }
  45. else
  46. continue;
  47.  
  48. //cout << endl << s << " Petla nr. " << i << endl << endl;
  49.  
  50. for (int k = 1; k < 3; k++) // Pętla w celu, gdy k = 2, usuwa 0 i dodaje do "c"
  51. {
  52. if (k == 2)
  53. {
  54. if (c % 10 == 0)
  55. continue;
  56.  
  57. s.erase(0, 1);
  58. cS = "0" + to_string(c);
  59.  
  60. poLewej = 4;
  61. }
  62. else
  63. cS = to_string(c);
  64.  
  65. do {
  66. #pragma omp parallel for schedule(dynamic, 4) num_threads(8)
  67. for (int j = poLewej; j < s.length(); j++)
  68. {
  69. b = stoi(s.substr(j, s.length()));
  70.  
  71. if (b != 0)
  72. {
  73. a = stoi(s.substr(0, j));
  74.  
  75. if ((a > b) && (a%b == 0))
  76. {
  77. sum = 0;
  78.  
  79. sum = (a / b) + c;
  80.  
  81. if (sum == 100)
  82. {
  83. cout << s.substr(0, j) << " / " << s.substr(j, s.length()) << " + " << cS << " = " << "100" << endl;
  84. cout << "Watek: " << omp_get_thread_num() << endl;
  85. licz++;
  86. }
  87. }
  88. }
  89. }
  90. licz_operacje++;
  91. } while (next_permutation(s.begin(), s.end()));
  92. if (k == 2)
  93. {
  94. s.insert(0, "0");
  95. }
  96. }
  97.  
  98. if (c > 9)
  99. {
  100. if (ld < lj)
  101. {
  102. s.insert(ld, to_string(ld));
  103. s.insert(lj, to_string(lj));
  104. }
  105. else
  106. {
  107. s.insert(lj, to_string(lj));
  108. s.insert(ld, to_string(ld));
  109. }
  110. }
  111. else
  112. s.insert(c, to_string(c));
  113. }
  114.  
  115. double stop = omp_get_wtime();
  116.  
  117. cout << "Czas wykonania: " << (stop - start) << endl;
  118. cout << "Operacje: " << licz_operacje << endl;
  119. cout << "Result: " << licz;
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement