Advertisement
Guest User

ORv2

a guest
Jan 21st, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <ctime>
  5. #include <omp.h>
  6. #include <vector>
  7.  
  8.  
  9. using namespace std;
  10. string firstStr, secondStr, thirdStr, getPermutation;
  11. int firstInt, secondInt, thirdInt, choose, k;
  12. int licz = 0;
  13. vector<string> readOut;
  14.  
  15. void sequency()
  16. {
  17. string s("0123456789");
  18. vector<string> tab;
  19.  
  20. cout << endl << "Rozpoczeto generowanie permutacji... ";
  21.  
  22. clock_t start = clock();
  23.  
  24. do {
  25. tab.push_back(s);
  26. } while (next_permutation(s.begin(), s.end()));
  27.  
  28. cout << " OK " << endl;
  29.  
  30. for (int k = 0; k < tab.size(); k++) {
  31. getPermutation = tab[k];
  32. for (int leftSide = 1; leftSide < getPermutation.length() - 1; leftSide++) {
  33. for (int rightSide = (getPermutation.length() - 1); rightSide > leftSide; rightSide--) {
  34. firstStr = getPermutation.substr(0, leftSide);
  35. firstInt = stoi(firstStr);
  36.  
  37. secondStr = getPermutation.substr(leftSide, (rightSide - leftSide));
  38. secondInt = stoi(secondStr);
  39.  
  40. thirdStr = getPermutation.substr(rightSide, (getPermutation.length() -rightSide));
  41. thirdInt = stoi(thirdStr);
  42.  
  43. if (secondInt != 0 && (firstInt%secondInt == 0) && ((firstInt / secondInt) + thirdInt == 100))
  44. {
  45. readOut.push_back(firstStr + " / " + secondStr + " + " + thirdStr + " = 100");
  46. licz++;
  47. cout << licz << endl;
  48. }
  49. if (thirdInt != 0 && (secondInt%thirdInt == 0) && (firstInt + (secondInt / thirdInt) == 100))
  50. {
  51. readOut.push_back(firstStr + " + " + secondStr + " / " + thirdStr + " = 100");
  52. licz++;
  53. cout << licz << endl;
  54. }
  55. }
  56. }
  57. }
  58.  
  59. clock_t stop = clock();
  60. cout << "Wygenerowano liczbe mozliwosci w liczbie: " << tab.size() << endl;
  61. cout << "Liczba znalezionych liczbe sposobow uzyskania wyniku 100: " << licz << endl;
  62. cout << "Czas realizacji: " << (stop - start) << endl;
  63. }
  64.  
  65. void menu()
  66. {
  67. system("cls");
  68. cout << "Program znajdujacy liczbe sposobow w jaki mozna wstawic operacje + i / pomiedzy cyfry 0, 1, . . ., 9 w taki sposob, aby powstale dzialanie dalo wynik rowny 100" << endl;
  69. cout << "MENU - wybierz interesujaca Cie opcje" << endl;
  70. cout << "1. Wyszukiwanie liczb w sposob sekwencyjny" << endl;
  71. cout << "2. Wyszukiwanie liczb w sposob rownoległy" << endl;
  72. cout << "Twoj wybor (zatwierdz ENTER`em): ";
  73. cin >> choose;
  74.  
  75. switch (choose)
  76. {
  77. case 1:
  78. sequency();
  79. default:
  80. cout << "Nie ma takiej opcji w MENU!" << endl;
  81. menu();
  82. }
  83. }
  84.  
  85.  
  86. int main()
  87. {
  88. omp_set_num_threads(4);
  89. menu();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement